Created
July 15, 2024 13:29
-
-
Save x1unix/9360dd5c118d52bca49c8f83f90ded89 to your computer and use it in GitHub Desktop.
self-destruct SW
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
// Self-destructible service worker stub | |
self.addEventListener('install', function(e) { | |
self.skipWaiting(); | |
}) | |
self.addEventListener('activate', function(e) { | |
self.registration.unregister() | |
.then(function () { | |
return self.clients.matchAll(); | |
}) | |
.then(function (clients) { | |
clients.forEach(client => { | |
if (client instanceof WindowClient) { | |
client.navigate(client.url) | |
} | |
}) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment