From c7df7be7f177294e6e70c6d2f8087563c8a48a7d Mon Sep 17 00:00:00 2001 From: Andrew Armbruster Date: Sun, 28 May 2023 14:15:55 +0200 Subject: [PATCH] Catch rejected Promise on failed fullscreen request Add a `catch()` rejection of request for fullscreen (standard Fullscreen API implementation), as well as fullscreen exit. For now there is no actual handling, but we send a message to the internal error channel. Motivation: The fullscreen request was causing certain tests to fail when run with newer versions of QUnit (starting in 2.5.0), which now fails tests that have unhandled Promise rejections (as we did here). The exit case is not currently covered by tests, but works the same way (also returns a promise). See: https://fullscreen.spec.whatwg.org/#ref-for-dom-element-requestfullscreen%E2%91%A0 --- src/fullscreen.js | 8 ++++++-- test/modules/basic.js | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fullscreen.js b/src/fullscreen.js index 9fa84f07..1b80464c 100644 --- a/src/fullscreen.js +++ b/src/fullscreen.js @@ -67,10 +67,14 @@ return document.fullscreenElement; }; fullScreenApi.requestFullScreen = function( element ) { - return element.requestFullscreen(); + return element.requestFullscreen().catch(function (msg) { + $.console.error('Fullscreen request failed: ', msg); + }); }; fullScreenApi.exitFullScreen = function() { - document.exitFullscreen(); + document.exitFullscreen().catch(function (msg) { + $.console.error('Error while exiting fullscreen: ', msg); + }); }; fullScreenApi.fullScreenEventName = "fullscreenchange"; fullScreenApi.fullScreenErrorEventName = "fullscreenerror"; diff --git a/test/modules/basic.js b/test/modules/basic.js index 457adeab..49c70365 100644 --- a/test/modules/basic.js +++ b/test/modules/basic.js @@ -224,7 +224,7 @@ }); QUnit.test('FullScreen', function(assert) { - var done = assert.async(); + const done = assert.async(); if (!OpenSeadragon.supportsFullScreen) { assert.expect(0); done(); @@ -234,7 +234,7 @@ viewer.addHandler("open", function () { assert.ok(!OpenSeadragon.isFullScreen(), 'Started out not fullscreen'); - var checkEnteringPreFullScreen = function(event) { + const checkEnteringPreFullScreen = function(event) { viewer.removeHandler('pre-full-screen', checkEnteringPreFullScreen); assert.ok(event.fullScreen, 'Switching to fullscreen'); assert.ok(!OpenSeadragon.isFullScreen(), 'Not yet fullscreen'); @@ -242,7 +242,7 @@ // The fullscreen mode is always denied during tests so we are // exiting directly. - var checkExitingFullScreen = function(event) { + const checkExitingFullScreen = function(event) { viewer.removeHandler('full-screen', checkExitingFullScreen); assert.ok(!event.fullScreen, 'Exiting fullscreen'); assert.ok(!OpenSeadragon.isFullScreen(), 'Disabled fullscreen');