feat: add debug safari not updating sw

This commit is contained in:
Ayo Ayco 2024-08-18 10:43:41 +02:00
parent 91067beb40
commit a967115ab9

View file

@ -46,6 +46,33 @@ const appTitle = article?.title ? `${article.title} | Cozy` : 'Cozy';
)
}
<link rel="shortcut icon" type="image/svg+xml" href="/favicon.svg" />
<script is:inline type="module">
async function handleUpdate() {
if ("serviceWorker"in navigator) {
let refreshing;
// check to see if there is a current active service worker
const oldSw = (await navigator.serviceWorker.getRegistration())?.active?.state;
navigator.serviceWorker.addEventListener('controllerchange', async () => {
if (refreshing) return;
// when the controllerchange event has fired, we get the new service worker
const newSw = (await navigator.serviceWorker.getRegistration())?.active?.state;
// if there was already an old activated service worker, and a new activating service worker, do the reload
if(oldSw === 'activated' && newSw === 'activating') {
refreshing = true;
window.location.reload();
}
});
}
}
console.log('something unique')
handleUpdate();
</script>
</head>
<body>
<div id="app-wrapper">