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 on the video like
MozDOMFullscreen:Request is special because it's a "chrome-only event". 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.
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).
: 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.