Skip to content

Instantly share code, notes, and snippets.

@SleepWalker
Last active December 10, 2018 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SleepWalker/d0b711de6420e150b82d2b65867e76a9 to your computer and use it in GitHub Desktop.
Save SleepWalker/d0b711de6420e150b82d2b65867e76a9 to your computer and use it in GitHub Desktop.
unregister service worker
// browser way
navigator.serviceWorker.getRegistrations().then(registrations => {
for (const registration of registrations) {
registration
.unregister()
.then(boolean => {
console.log(
boolean ? '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`,
);
});
}
});
// sw way
self.addEventListener('activate', () => {
self.registration
.unregister()
.then(() => 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