From 146008f610c3406cca4d3e282c41d9ad1fedbb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Tue, 4 Jul 2023 13:43:09 +0200 Subject: [PATCH] Use pagehide instead of unload for PiP (#8321) --- src/js/player.js | 4 ++-- test/unit/player.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index d855b9f4b..604a78ec5 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -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); @@ -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(); } diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 5d5ce27af..e283838e9 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -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; };