Last active
December 10, 2018 07:45
-
-
Save SleepWalker/d0b711de6420e150b82d2b65867e76a9 to your computer and use it in GitHub Desktop.
unregister 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
// 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
sources: