tiny-pilot / tinypilot

Use your Raspberry Pi as a browser-based KVM.
https://tinypilotkvm.com
MIT License
3k stars 252 forks source link

Empty screen in Dedicated Window mode #1609

Closed mtlynch closed 1 year ago

mtlynch commented 1 year ago

Description

Going to View > Dedicated Window pops an empty window:

image

Repro steps

  1. Install TinyPilot Pro Voyager pre-build: https://app.circleci.com/pipelines/github/tiny-pilot/tinypilot-pro/3329/workflows/923c916a-50a1-458e-b2c7-cd73b834886a/jobs/28426
  2. From Win10 + Firefox 116 client, go to View > Dedicated Window

Logs

The console logs include lots of "can't access dead object" errors:

Uncaught TypeError: can't access dead object
    connectedCallback https://tinypilot/?viewMode=standalone:122
    <anonymous> https://tinypilot/?viewMode=standalone:102
    <anonymous> https://tinypilot/?viewMode=standalone:202

The first line in the stacktrace points to this line:

       connectedCallback() {
          this.attachShadow({ mode: "open" }).appendChild( <<< failure
            template.content.cloneNode(true)
          );

Notes

This is on a branch build to test something else, but I suspect it's unrelated to the branch changes. I'll try re-testing on a master build.

mtlynch commented 1 year ago

This seems to be specific to Firefox. I can't reproduce it in Chrome or Edge.

mtlynch commented 1 year ago

This happens in dev mode as well, so we don't even need a full build to repro this.

mtlynch commented 1 year ago

I think what's happening is that Firefox is somehow sharing resources between the original window and the popup. And it looks like this is the sequence:

  1. Create the popup
  2. Close the original window
  3. Finish loading the popup

It looks like Firefox tries to share resources between the original window and the popup, but after step (2), it garbage collects those resources, so the popup tries to re-use them but they're already garbage collected, which is causing the "can't access dead object" errors.

Adding noopener to window.open seems to fix it because it forces the popup to use independent resources.

I also notice that commenting out the window.location call fixes it. And we can fix the issue by wrapping the window.location call in a setTimeout(..., 500), but that's flakier because we're just guessing how long it will take for the popup to load.