24 lines
670 B
JavaScript
24 lines
670 B
JavaScript
(async function () {
|
|
console.log("Registering service worker...");
|
|
if ("serviceWorker" in navigator) {
|
|
try {
|
|
const registration = await navigator.serviceWorker.register(
|
|
"sw.js",
|
|
{
|
|
scope: window.location.path,
|
|
},
|
|
);
|
|
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");
|
|
}
|
|
console.log(registration);
|
|
} catch (error) {
|
|
console.error(`Registration failed with ${error}`);
|
|
}
|
|
}
|
|
})();
|