From d120a6aa3d2cb62cd36ca4980ab27ef86ac006f1 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 28 Sep 2023 15:11:17 +0800 Subject: [PATCH] Dont use the service worker cache as it interferes with the content security policy If we use this, then the CSP can't set security policies as granularly, as almost everything will go through connect-src, like every time we get a fallback image it would go through fetch and connect-src would have to allow all https. --- packages/web/public/sw.js | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/web/public/sw.js b/packages/web/public/sw.js index 13e50a124..a7f1f8728 100644 --- a/packages/web/public/sw.js +++ b/packages/web/public/sw.js @@ -129,23 +129,6 @@ }) } - function handleFetchRequest(ev) { - const request = ev.request - if (request.method === 'POST') { - const requestUrl = new URL(request.url) - if (requestUrl.pathname === '/share-target') { - const shareRequest = handleShareTarget(request) - return shareRequest - } - } - - if (naviApi.onLine) { - return globalApi.fetch(request) - } - - return fetchWithCacheBackup(request) - } - function handleOutdatedCache() { return globalApi.caches.keys().then((cacheNames) => { return Promise.all( @@ -181,8 +164,16 @@ if (ev.request.destination === 'script') { return } + if (ev.request.destination === 'image') { + return + } - const handler = handleFetchRequest(ev) - ev.respondWith(handler) + if (ev.request.method === 'POST') { + const requestUrl = new URL(request.url) + if (requestUrl.pathname === '/share-target') { + const shareRequest = handleShareTarget(request) + return shareRequest + } + } }) })()