test code for sw state changes
This commit is contained in:
parent
eaaf18fb82
commit
e290822a32
1 changed files with 16 additions and 2 deletions
18
index.html
18
index.html
|
@ -29,10 +29,24 @@
|
|||
}
|
||||
});
|
||||
</script>
|
||||
<script id="service-worker" type="disabled">
|
||||
<script id="service-worker" type="module">
|
||||
if('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('sw.js')
|
||||
.then(function() { console.log("Service Worker registered"); });
|
||||
.then(function(registration) {
|
||||
console.log("Service Worker registered");
|
||||
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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
Reference in a new issue