Created
March 24, 2022 18:26
-
-
Save wesbos/c7ef39586e6174effc6680d8b8799571 to your computer and use it in GitHub Desktop.
Nuke a service worker from inside a service worker
This file contains 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
// put this in a file where your service worker used to live, like yourdomain.com/service-worker.js. You can find out this path in the SW dev tools of your browser | |
self.addEventListener('install', (e) => { | |
console.log('[Service Worker] Installing Service Worker ...', e); | |
self.skipWaiting(); | |
}); | |
self.addEventListener('activate', (e) => { | |
console.log('[ServiceWorker] Activate'); | |
self.registration | |
.unregister() | |
.then(() => self.clients.matchAll()) | |
.then((clients) => { | |
console.log(clients); | |
clients.forEach((client) => client.navigate(client.url)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment