From d31371b4865e53a7ada510b015c0ea9936ea336e Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 8 Nov 2021 14:37:32 +0530 Subject: [PATCH 1/5] Return on upload in sw --- src/platform/web/docroot/sw.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/web/docroot/sw.js b/src/platform/web/docroot/sw.js index 29b124d9..21fdf2d2 100644 --- a/src/platform/web/docroot/sw.js +++ b/src/platform/web/docroot/sw.js @@ -69,6 +69,9 @@ async function purgeOldCaches() { } self.addEventListener('fetch', (event) => { + if (event.request.url.indexOf("upload") !== -1) { + return; + } event.respondWith(handleRequest(event.request)); }); From d1491cc2033cae8d666eaf6e0840514d99c29e10 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 8 Nov 2021 15:11:41 +0530 Subject: [PATCH 2/5] More checks before returning --- src/platform/web/docroot/sw.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/web/docroot/sw.js b/src/platform/web/docroot/sw.js index 21fdf2d2..9b5da128 100644 --- a/src/platform/web/docroot/sw.js +++ b/src/platform/web/docroot/sw.js @@ -68,8 +68,10 @@ async function purgeOldCaches() { } } -self.addEventListener('fetch', (event) => { - if (event.request.url.indexOf("upload") !== -1) { +self.addEventListener('fetch', async (event) => { + if (event.request.method === "POST" && + (await event.request.blob()).type !== "application/json" && + event.request.body) { return; } event.respondWith(handleRequest(event.request)); From c1a8ffd814083c7003cbadac088e2d1239c9ba2f Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 8 Nov 2021 18:03:20 +0530 Subject: [PATCH 3/5] respond with only for GET requests --- src/platform/web/docroot/sw.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/platform/web/docroot/sw.js b/src/platform/web/docroot/sw.js index 9b5da128..7eab4758 100644 --- a/src/platform/web/docroot/sw.js +++ b/src/platform/web/docroot/sw.js @@ -69,12 +69,9 @@ async function purgeOldCaches() { } self.addEventListener('fetch', async (event) => { - if (event.request.method === "POST" && - (await event.request.blob()).type !== "application/json" && - event.request.body) { - return; + if (event.request.method === "GET") { + event.respondWith(handleRequest(event.request)); } - event.respondWith(handleRequest(event.request)); }); function isCacheableThumbnail(url) { From 57e2c4ea45205195b29858dd16e508d5621a55f1 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 8 Nov 2021 22:20:56 +0530 Subject: [PATCH 4/5] No need for handler to be async --- src/platform/web/docroot/sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/web/docroot/sw.js b/src/platform/web/docroot/sw.js index 7eab4758..8542492c 100644 --- a/src/platform/web/docroot/sw.js +++ b/src/platform/web/docroot/sw.js @@ -68,7 +68,7 @@ async function purgeOldCaches() { } } -self.addEventListener('fetch', async (event) => { +self.addEventListener('fetch', (event) => { if (event.request.method === "GET") { event.respondWith(handleRequest(event.request)); } From 8fba3f4ca9d40ee5c3c1ea6084d74c7b7552b964 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 9 Nov 2021 15:39:24 +0530 Subject: [PATCH 5/5] Add explaining comment --- src/platform/web/docroot/sw.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/platform/web/docroot/sw.js b/src/platform/web/docroot/sw.js index 8542492c..1dbe21f9 100644 --- a/src/platform/web/docroot/sw.js +++ b/src/platform/web/docroot/sw.js @@ -69,6 +69,11 @@ async function purgeOldCaches() { } self.addEventListener('fetch', (event) => { + /* + service worker shouldn't handle xhr uploads because otherwise + the progress events won't fire. + This has to do with xhr not being supported in service workers. + */ if (event.request.method === "GET") { event.respondWith(handleRequest(event.request)); }