Skip to content

Commit 077077b

Browse files
mister-bengkatsev
andauthored
fix: Don't request fullscreen from document PIP window (#8881)
## Description Double clicking the document pip window requests fullscreen but this fails. The gesture on the pip window can't initiate fullscreen. Fixes #8877 ## Specific Changes proposed Change the default double click action to just exit pip. This is the same behaviour as before without the error, as requestFullScreen() calls exitPictureInPicture(); --------- Co-authored-by: Gary Katsevman <[email protected]>
1 parent b1dee92 commit 077077b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/js/player.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,8 @@ class Player extends Component {
20032003
}
20042004

20052005
/**
2006-
* Handle a double-click on the media element to enter/exit fullscreen
2006+
* Handle a double-click on the media element to enter/exit fullscreen,
2007+
* or exit documentPictureInPicture mode
20072008
*
20082009
* @param {Event} event
20092010
* the event that caused this function to trigger
@@ -2045,7 +2046,12 @@ class Player extends Component {
20452046
) {
20462047

20472048
this.options_.userActions.doubleClick.call(this, event);
2048-
2049+
} else if (this.isInPictureInPicture() && !document.pictureInPictureElement) {
2050+
// Checking the presence of `window.documentPictureInPicture.window` complicates
2051+
// tests, checking `document.pictureInPictureElement` also works. It wouldn't
2052+
// be null in regular picture in picture.
2053+
// Exit picture in picture mode. This gesture can't trigger pip on the main window.
2054+
this.exitPictureInPicture();
20492055
} else if (this.isFullscreen()) {
20502056
this.exitFullscreen();
20512057
} else {

test/unit/player-user-actions.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ QUnit.test('by default, double-click opens fullscreen', function(assert) {
151151
assert.strictEqual(this.player.exitFullscreen.callCount, 1, 'has exited fullscreen');
152152
});
153153

154+
QUnit.test('in document picture in picture mode, double-click exits pip', function(assert) {
155+
this.player.isInPictureInPicture = () => true;
156+
this.player.exitPictureInPicture = sinon.spy();
157+
this.player.requestFullscreen = sinon.spy();
158+
this.player.exitFullscreen = sinon.spy();
159+
160+
this.player.handleTechDoubleClick_({target: this.player.tech_.el_});
161+
162+
assert.strictEqual(this.player.exitPictureInPicture.callCount, 1, 'has exited pip once');
163+
assert.strictEqual(this.player.requestFullscreen.callCount, 0, 'has not entered fullscreen');
164+
assert.strictEqual(this.player.exitFullscreen.callCount, 0, 'has not exited fullscreen');
165+
});
166+
154167
QUnit.test('when controls are disabled, double-click does nothing', function(assert) {
155168
let fullscreen = false;
156169

0 commit comments

Comments
 (0)