When a Picture-in-Picture player window is open, we have code that's watching the underlying <video> element that's being PiP'd for changes. Going into fullscreen is one of those changes that we want to monitor for. When we see that change, we should tell Firefox to close the PiP player window. Here's where we add event listeners for the <video>: https://searchfox.org/mozilla-central/rev/eb9d5c97927aea75f0c8e38bbc5b5d288099e687/toolkit/actors/PictureInPictureChild.jsm#1237-1240 The event we want to listen for is `MozDOMFullscreen:Request`. This is a special event - unlike the other [media events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events) on the video like `play` and `pause`, `MozDOMFullscreen:Request` is special because it's a "chrome-only event"[1]. This means we have to listen to it specially - you'll need to get to the <video> element's "chrome event handler" on the window that it belongs to, and call `addEventListener` on that. Something like this: ``` let chromeEventHandler = originatingWindow.docShell.chromeEventHandler; ... chromeEventHandler.addEventListener("MozDOMFullscreen:Request", this, true); ``` don't forget to remove the listener in the `untrackOriginatingVideo` method too! Then, you'll want to add a handler for that event in the switch statement here: https://searchfox.org/mozilla-central/rev/eb9d5c97927aea75f0c8e38bbc5b5d288099e687/toolkit/actors/PictureInPictureChild.jsm#1004-1061 and roughly do the same thing that "pagehide" does, which is to call `closePictureInPicture`. You'll want to pass a different reason though - probably "fullscreen" instead. That `reason` property is used as part of our Telemetry that measures the different ways that the player is closed. A site that you can test this behaviour on is Vimeo - perhaps this video: https://vimeo.com/415176232?ref=tw-share I recommend this over YouTube, because it seems as if lately YouTube is doing something that causes the PiP player window to close when going into fullscreen (probably because they're swapping out the <video> element or something). [1]: The term "chrome" means "elevated privileges because it's part of the browser UI". This term existed before the Chrome browser. Presumably, they named their browser after this term, which has added to much confusion.
Bug 1534986 Comment 8 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
When a Picture-in-Picture player window is open, we have code that's watching the underlying <video> element that's being PiP'd for changes. Going into fullscreen is one of those changes that we want to monitor for. When we see that change, we should tell Firefox to close the PiP player window. Here's where we add event listeners for the <video>: https://searchfox.org/mozilla-central/rev/eb9d5c97927aea75f0c8e38bbc5b5d288099e687/toolkit/actors/PictureInPictureChild.jsm#1237-1240 The event we want to listen for is `MozDOMFullscreen:Request`. This is a special event - unlike the other [media events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events) on the video like `play` and `pause`, `MozDOMFullscreen:Request` is special because it's a "chrome-only event"[1]. This means we have to listen to it specially - you'll need to get to the <video> element's "chrome event handler" on the window that it belongs to, and call `addEventListener` on that. Something like this: ```javascript let chromeEventHandler = originatingWindow.docShell.chromeEventHandler; ... chromeEventHandler.addEventListener("MozDOMFullscreen:Request", this, true); ``` don't forget to remove the listener in the `untrackOriginatingVideo` method too! Then, you'll want to add a handler for that event in the switch statement here: https://searchfox.org/mozilla-central/rev/eb9d5c97927aea75f0c8e38bbc5b5d288099e687/toolkit/actors/PictureInPictureChild.jsm#1004-1061 and roughly do the same thing that "pagehide" does, which is to call `closePictureInPicture`. You'll want to pass a different reason though - probably "fullscreen" instead. That `reason` property is used as part of our Telemetry that measures the different ways that the player is closed. A site that you can test this behaviour on is Vimeo - perhaps this video: https://vimeo.com/415176232?ref=tw-share I recommend this over YouTube, because it seems as if lately YouTube is doing something that causes the PiP player window to close when going into fullscreen (probably because they're swapping out the <video> element or something). [1]: The term "chrome" means "elevated privileges because it's part of the browser UI". This term existed before the Chrome browser. Presumably, they named their browser after this term, which has added to much confusion.