mirror of
https://github.com/9001/copyparty.git
synced 2026-06-18 20:22:27 -06:00
PWA: wip service worker registration
This commit is contained in:
parent
0135a925d9
commit
d80f3b76c5
|
|
@ -4,7 +4,7 @@
|
|||
if ('serviceWorker' in navigator) {
|
||||
self.addEventListener("fetch", (event) => {
|
||||
// Regular requests not related to Web Share Target.
|
||||
if (event.request.method !== "POST" || !event.request.enctype.has("share-target")) {
|
||||
if (event.request.method !== "POST" || !event.request.action.has("share-target")) {
|
||||
event.respondWith(fetch(event.request));
|
||||
return;
|
||||
}
|
||||
|
|
@ -23,21 +23,4 @@ if ('serviceWorker' in navigator) {
|
|||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.register("/.cpr/w/sw.js", {
|
||||
scope: "/",
|
||||
});
|
||||
if (registration.installing) {
|
||||
console.log("Service worker installing");
|
||||
} else if (registration.waiting) {
|
||||
console.log("Service worker installed");
|
||||
} else if (registration.active) {
|
||||
console.log("Service worker active");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Registration failed with ${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -2421,4 +2421,25 @@ function xhrchk(xhr, prefix, e404, lvl, tag) {
|
|||
return fun(0, prefix + xhr.status + ": " + errtxt, tag);
|
||||
}
|
||||
|
||||
// register service worker
|
||||
// ToDo: set http header: Service-Worker-Allowed: /
|
||||
// otherwise it will fail to register
|
||||
// https://stackoverflow.com/questions/49084718/how-exactly-add-service-worker-allowed-to-register-service-worker-scope-in-upp
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.register("/.cpr/w/sw.js", {
|
||||
scope: "/",
|
||||
});
|
||||
if (registration.installing) {
|
||||
console.log("Service worker installing");
|
||||
} else if (registration.waiting) {
|
||||
console.log("Service worker installed");
|
||||
} else if (registration.active) {
|
||||
console.log("Service worker active");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Registration failed with ${error}`);
|
||||
}
|
||||
});
|
||||
|
||||
J_UTL = 2;
|
||||
|
|
|
|||
Loading…
Reference in a new issue