Open Bug 1561301 Opened 5 years ago Updated 6 months ago

Allow Picture-in-Picture player window to continue playing if originating tab closes

Categories

(Toolkit :: Picture-in-Picture, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: mconley, Unassigned, NeedInfo)

References

(Blocks 2 open bugs)

Details

Attachments

(1 file)

I'm not sure how possible this is, but it's something that was discussed in Whistler as a way of differentiating our Picture-in-Picture implementation.

We'd need a way of keeping the original <video> element (or, at least, it's stream of data and decoder) alive after the originating tab / window closes.

Blocks: videopip
No longer blocks: 1532675

One way of doing this is by hiding any tab with a PiP player window open instead of closing it.

I just thought up an approach to this, and I wanted to get it down before I forget:

When closing a tab that's using PiP, we could create a new <browser> inside of the player window, and swap frameloaders with the original tab, and then close the original tab. This would be effectively like dragging the originating tab into an invisible space within the player window. This would keep the DOM content alive, and would keep the video running. The document would remain alive until the player window is closed.

There would have to be some kind of consideration about what to do in the event that the site tried to do something that would normally cause some UI to be presented to the user (for example, requesting geolocation access). I imagine, however, that we might be able to treat the hidden browser like we treat the thumbnail browser, and deny all permissions after it goes into this state.

(In reply to Mike Conley (:mconley) (:⚙️) from comment #4)

I really like this idea. If the permission thing becomes a problem, we can add a button to swap the browser back into a real window and show the permission prompt upon the completed swap.

Blocks: 1662870
Blocks: 1685549
No longer blocks: 1662870
Assignee: nobody → popeoliv
Status: NEW → ASSIGNED

(In reply to Mike Conley (:mconley) (:⚙️) (Catching up on needinfos) from comment #4)

When closing a tab that's using PiP, we could create a new <browser> inside of the player window, and swap frameloaders with the original tab, and then close the original tab.

Hey Mike, Oliver and I have tried experimenting with this recently. For myself, I've attempted doing what PaymentUIService._moveDialogToNewBrowser does for swapping frameloaders but adjusted for PiP:

When "TabClose" event occurs on the original tab:

  saveTab(event) {
    let browser = event.target.linkedBrowser;
    for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
      // Get the associated PiP window of the closing tab
      if (this.weakWinToBrowser.get(win) === browser) {
        // Create a new <browser> to preserve the DOM content 
        let frame = win.document.createXULElement("browser");
        frame.setAttribute("type", "content");
        frame.setAttribute("remote", "true");
        
        // Set append the new <browser> element to the PiP player document (will need some styling)
        let container = win.document.getElementById("saved-tabs-container");
        container.appendChild(frame);

        // Swap frameloaders between the original tab's browser to the new one
        frame.swapFrameLoaders(browser);
      }
    }
  },

But at swapFrameLoaders I get NS_ERROR_NOT_IMPLEMENTED: thrown in the browser console. I'm wondering if you might have any ideas about what I might be doing wrong here (and what the error means here).

Flags: needinfo?(mconley)
Component: Video/Audio Controls → Picture-in-Picture
Version: 68 Branch → Trunk
Assignee: popeoliv → nobody
Status: ASSIGNED → NEW
Severity: normal → S3
Duplicate of this bug: 1584880
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: