From 24a317a836778f16b16916f1a1b6b939f0a418d8 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 27 Apr 2022 11:31:50 +0100 Subject: [PATCH] Catch navigator.serviceWorker.getRegistrations() Promise rejection (#7708) GitOrigin-RevId: 4c68e4272ea9618503ad655dd6c24841486601b2 --- .../features/pdf-preview/util/service-worker.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/util/service-worker.js b/services/web/frontend/js/features/pdf-preview/util/service-worker.js index 7d0fe6ac95..dec3b473ad 100644 --- a/services/web/frontend/js/features/pdf-preview/util/service-worker.js +++ b/services/web/frontend/js/features/pdf-preview/util/service-worker.js @@ -56,10 +56,18 @@ export function unregisterServiceWorker() { type: 'disable', }) } - navigator.serviceWorker.getRegistrations().then(registrations => { - registrations.forEach(worker => { - worker.unregister() + + navigator.serviceWorker + .getRegistrations() + .catch(error => { + // fail silently if permission not given (e.g. SecurityError) + console.error('error listing service worker registrations', error) + return [] + }) + .then(registrations => { + registrations.forEach(worker => { + worker.unregister() + }) }) - }) } }