Catch navigator.serviceWorker.getRegistrations() Promise rejection (#7708)

GitOrigin-RevId: 4c68e4272ea9618503ad655dd6c24841486601b2
This commit is contained in:
Alf Eaton 2022-04-27 11:31:50 +01:00 committed by Copybot
parent 77747a0aca
commit 24a317a836

View file

@ -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()
})
})
})
}
}