[fix] sw reloading when unregistered

This commit is contained in:
kwaroran
2023-05-07 16:27:53 +09:00
parent b0b8697821
commit 35c52aff40
2 changed files with 9 additions and 3 deletions

View File

@@ -105,7 +105,7 @@ export async function getFileSrc(loc:string) {
}
return "/sw/img/" + encoded
} catch (error) {
location.reload()
}
}
else{
@@ -252,9 +252,15 @@ export async function loadData() {
}
if(navigator.serviceWorker){
usingSw = true
const rej = await navigator.serviceWorker.register("/sw.js", {
await navigator.serviceWorker.register("/sw.js", {
scope: "/"
});
await sleep(100)
const da = await fetch('/sw/init')
if(!(da.status >= 200 && da.status < 300)){
location.reload()
}
}
else{
usingSw = false