From a6eff1e371435d7b7f7f206069410b8ff703fa0a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 4 May 2022 16:09:39 +0200 Subject: [PATCH] Service worker not over HTTP --- packages/web/boot.ts | 16 +++++++++++----- packages/web/service_worker.ts | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/web/boot.ts b/packages/web/boot.ts index 4440c84..5601181 100644 --- a/packages/web/boot.ts +++ b/packages/web/boot.ts @@ -56,11 +56,17 @@ safeRun(async () => { // if (!isDesktop) { // if (localStorage.getItem("disable_sw") !== "true") { -navigator.serviceWorker - .register(new URL("service_worker.ts", import.meta.url), { type: "module" }) - .then((r) => { - console.log("Service worker registered..."); - }); +if (navigator.serviceWorker) { + navigator.serviceWorker + .register(new URL("service_worker.ts", import.meta.url), { type: "module" }) + .then((r) => { + console.log("Service worker registered..."); + }); +} else { + console.log( + "No launching service worker (not present, maybe because not running on localhost or over SSL" + ); +} // } // } diff --git a/packages/web/service_worker.ts b/packages/web/service_worker.ts index 7a144f3..7669820 100644 --- a/packages/web/service_worker.ts +++ b/packages/web/service_worker.ts @@ -2,11 +2,11 @@ import { manifest, version } from "@parcel/service-worker"; async function install() { const cache = await caches.open(version); - console.log("Installing", manifest, "version", version); + // console.log("Installing", manifest, "version", version); await cache.addAll(manifest); // @ts-ignore self.skipWaiting(); // This automatically enables the service worker, preventing from caching stuff forever if there's a page open - console.log("Installed"); + // console.log("Installed"); } //@ts-ignore