From 5292080a8a6c4052820162f3d9f85ee2a96711a2 Mon Sep 17 00:00:00 2001 From: Peter Piekarczyk Date: Mon, 3 Apr 2023 09:56:10 -0500 Subject: [PATCH] add more debugging (#3559) --- .../background/src/service-worker-loader.html | 4 ++++ packages/background/src/service-worker.ts | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/background/src/service-worker-loader.html b/packages/background/src/service-worker-loader.html index 2976b2a5b..b53f0afb1 100644 --- a/packages/background/src/service-worker-loader.html +++ b/packages/background/src/service-worker-loader.html @@ -21,6 +21,8 @@ const bodyElement = document.getElementsByTagName("body")[0]; bodyElement.appendChild(urlDiv); + console.log("currentUrlHash", currentUrlHash) + // check to see if an old service worker needs to be unregistered const registrations = await navigator.serviceWorker.getRegistrations(); console.log("# SERVICE WORKERS", registrations.length); @@ -32,6 +34,8 @@ .split("background-scripts/")[1] .split("/")[0]; + console.log("hash", hash) + if (currentUrlHash !== hash) { console.log("SERVICE WORKER: unregistering", registration); await registration.unregister(); diff --git a/packages/background/src/service-worker.ts b/packages/background/src/service-worker.ts index eb9a5c633..aa548acb1 100644 --- a/packages/background/src/service-worker.ts +++ b/packages/background/src/service-worker.ts @@ -5,37 +5,42 @@ import { postMessageToIframe } from "./shared"; import { start } from "."; let isStarted = false; +console.log("window:isStarted", isStarted); self.addEventListener("install", async () => { - console.log("installing"); + console.log("install:isStarted", isStarted); if (!isStarted) { start({ isMobile: true }); } - console.log("is mobile true, installed"); - // actives the current service worker immediately + console.log("install:skipWaiting..."); await self.skipWaiting(); + console.log("install:skipped..."); isStarted = true; // called after skipWaiting to ensure its only called once }); self.addEventListener("activate", async (event) => { - console.log("activated"); + console.log("activate:isStarted", isStarted); // Override default behavior of service worker and claim the page without having to reload the page + console.log("activate:waitUntil..."); await event.waitUntil(clients.claim()); - console.log("activating, claimed"); + console.log("activate:claimed"); if (!isStarted) { start({ isMobile: true }); isStarted = true; } + console.log("activate:postMessageToIframe..."); await postMessageToIframe({ type: BACKGROUND_SERVICE_WORKER_READY }); + console.log("activate:posted"); }); self.addEventListener("fetch", () => { + console.log("fetch:isStarted", isStarted); // Start the service worker if it hasn't been started yet if (!isStarted) { start({ isMobile: true });