From f37c16167dd101fbc9152f17c64afd213905e4e9 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Thu, 2 Jan 2025 14:08:51 -0500 Subject: [PATCH] service worker debugging --- static/demos/light-dark-superior_v1/script.js | 2 +- static/demos/light-dark-superior_v1/sw.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/static/demos/light-dark-superior_v1/script.js b/static/demos/light-dark-superior_v1/script.js index 59135ab..f9a63c7 100644 --- a/static/demos/light-dark-superior_v1/script.js +++ b/static/demos/light-dark-superior_v1/script.js @@ -39,6 +39,6 @@ else setupServiceWorker(); async function setupServiceWorker() { await navigator.serviceWorker.register("sw.js", { // we only need to interact with index.html for this demo - scope: "./index.html" + scope: "./" }); } diff --git a/static/demos/light-dark-superior_v1/sw.js b/static/demos/light-dark-superior_v1/sw.js index b8ce162..4685f00 100644 --- a/static/demos/light-dark-superior_v1/sw.js +++ b/static/demos/light-dark-superior_v1/sw.js @@ -19,10 +19,12 @@ async function fetchResponse(event) { } // this is a brittle way of accomplishing our desired behavior body.replace(``, - ``) + ``); + return new Response(body, resp); } self.addEventListener('fetch', (event) => { + if (!event.request.url.endsWith(".html")) return; //https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith event.respondWith(fetchResponse(event)); })