deregister sw when update is ready to go to force activating on iOS

This commit is contained in:
Bruno Windels 2020-10-15 15:59:15 +02:00
parent 6b15e7e3ba
commit 3354d601d1

View File

@ -31,19 +31,19 @@
</script>
<script id="service-worker" type="module">
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js')
.then(function(registration) {
navigator.serviceWorker.register('sw.js').then(function(registration) {
console.log("Service Worker registered");
function tryActivateUpdate() {
if (registration.waiting && registration.active) {
registration.unregister();
console.log("Service Worker unregistered");
}
}
tryActivateUpdate();
registration.onupdatefound = function() {
const newWorker = registration.installing;
alert("update found!");
newWorker.onstatechange = function() {
if (newWorker.state === "installed") {
alert("new worker is now on state " + newWorker.state);
// if (confirm("update installed! shall I skip waiting?")) {
// newWorker.skipWaiting();
// }
}
tryActivateUpdate();
}
};
});