Last active
October 12, 2024 23:39
-
-
Save loggerhead/6feeb566fff006b855c501817553a897 to your computer and use it in GitHub Desktop.
how to uninstall a service worker, code from https://love2dev.com/blog/how-to-uninstall-a-service-worker/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
navigator.serviceWorker.getRegistrations().then((registrations) => { | |
if (!registrations.length) { | |
console.log('No serviceWorker registrations found.') | |
return | |
} | |
for (const registration of registrations) { | |
registration | |
.unregister() | |
.then((isSucc) => { | |
console.log( | |
(isSucc ? 'Successfully unregistered' : 'Failed to unregister'), 'ServiceWorkerRegistration\n' + | |
(registration.installing ? ' .installing.scriptURL = ' + registration.installing.scriptURL + '\n' : '') + | |
(registration.waiting ? ' .waiting.scriptURL = ' + registration.waiting.scriptURL + '\n' : '') + | |
(registration.active ? ' .active.scriptURL = ' + registration.active.scriptURL + '\n' : '') + | |
' .scope: ' + registration.scope + '\n' | |
) | |
return self.clients.matchAll(); | |
}) | |
.then((clients) => { | |
clients.forEach((client) => { | |
if (client.url && "navigate" in client) { | |
client.navigate(client.url); | |
} | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment