Skip to content

Commit

Permalink
Use pagehide instead of unload for PiP (#8321)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored Jul 4, 2023
1 parent b34cb2c commit 146008f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3107,7 +3107,7 @@ class Player extends Component {
this.player_.trigger('enterpictureinpicture');

// Listen for the PiP closing event to move the video back.
pipWindow.addEventListener('unload', (event) => {
pipWindow.addEventListener('pagehide', (event) => {
const pipVideo = event.target.querySelector('.video-js');

pipContainer.replaceWith(pipVideo);
Expand Down Expand Up @@ -3142,7 +3142,7 @@ class Player extends Component {
*/
exitPictureInPicture() {
if (window.documentPictureInPicture && window.documentPictureInPicture.window) {
// With documentPictureInPicture, Player#leavepictureinpicture is fired in the unload handler
// With documentPictureInPicture, Player#leavepictureinpicture is fired in the pagehide handler
window.documentPictureInPicture.window.close();
return Promise.resolve();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2925,7 +2925,7 @@ QUnit.test('docPiP moves player and triggers events', function(assert) {
return fakePiPWindow.document.body.querySelector(sel);
};
fakePiPWindow.close = function() {
fakePiPWindow.dispatchEvent(new Event('unload'));
fakePiPWindow.dispatchEvent(new Event('pagehide'));
delete window.documentPictureInPicture.window;
};

Expand Down

0 comments on commit 146008f

Please sign in to comment.