From 5a275743bfd93acb03ec957ea95c68cb017de3a2 Mon Sep 17 00:00:00 2001 From: Russ Garrett Date: Thu, 23 May 2024 21:29:59 +0100 Subject: [PATCH] Only handle sameOrigin routes --- web/src/sw.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/src/sw.ts b/web/src/sw.ts index 4b6a024..4ee9b5f 100644 --- a/web/src/sw.ts +++ b/web/src/sw.ts @@ -8,7 +8,10 @@ declare let self: ServiceWorkerGlobalScope function register(match_url: string, strategy: any) { const prefix = '/' - registerRoute(({ url }) => url.pathname.startsWith(prefix + match_url), strategy) + registerRoute( + ({ url, sameOrigin }) => sameOrigin && url.pathname.startsWith(prefix + match_url), + strategy + ) } precacheAndRoute(self.__WB_MANIFEST) @@ -21,7 +24,10 @@ register('maps', new NetworkFirst()) try { // Only catch requests to the root URL (a regex doesn't do this). - registerRoute(({ url }) => url.pathname == '/', createHandlerBoundToURL('index.html')) + registerRoute( + ({ url, sameOrigin }) => sameOrigin && url.pathname == '/', + createHandlerBoundToURL('index.html') + ) } catch (e) { // This fails in dev as index.html is not in the manifest. }