From c6fc098bfe37cdd4417d3c746f48212beb5c9ea3 Mon Sep 17 00:00:00 2001 From: englishextra Date: Tue, 29 Sep 2020 22:11:33 +0300 Subject: [PATCH] I keep having the same error so I added this if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') return And all errors are gone :-) https://github.com/meanbee/magento-meanbee-pwa/issues/20#issuecomment-497626347 --- .../1.1.1/serviceWorker2/src/pwabuilder-sw.fixed.js | 8 ++++++++ sw.js | 9 +++++++++ sw.min.js | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cdn/pwabuilder-serviceworkers/1.1.1/serviceWorker2/src/pwabuilder-sw.fixed.js b/cdn/pwabuilder-serviceworkers/1.1.1/serviceWorker2/src/pwabuilder-sw.fixed.js index f039fff..e6aab06 100644 --- a/cdn/pwabuilder-serviceworkers/1.1.1/serviceWorker2/src/pwabuilder-sw.fixed.js +++ b/cdn/pwabuilder-serviceworkers/1.1.1/serviceWorker2/src/pwabuilder-sw.fixed.js @@ -39,6 +39,14 @@ self.addEventListener("fetch", function (event) { }; event.waitUntil(updateCache(event.request)); + + /*! + * https://github.com/meanbee/magento-meanbee-pwa/issues/20#issuecomment-497626347 + */ + + if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") { + return; + } event.respondWith( fetch(event.request).catch (function (error) { diff --git a/sw.js b/sw.js index baa0c9f..b525b58 100644 --- a/sw.js +++ b/sw.js @@ -40,6 +40,15 @@ self.addEventListener("fetch", function(event) { }; event.waitUntil(updateCache(event.request)); + + /*! + * https://github.com/meanbee/magento-meanbee-pwa/issues/20#issuecomment-497626347 + */ + + if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") { + return; + } + event.respondWith( fetch(event.request).catch(function(error) { console.log( diff --git a/sw.min.js b/sw.min.js index c1e369e..eb0c03d 100644 --- a/sw.min.js +++ b/sw.min.js @@ -1,2 +1 @@ -var cacheName="noushevr.github.io-offline-v1548146419";self.addEventListener("install",function(e){var n=new Request("index.html");e.waitUntil(fetch(n).then(function(t){return caches.open(cacheName).then(function(e){return e.put(n,t)})}))}),self.addEventListener("fetch",function(t){var n;t.waitUntil((n=t.request,caches.open(cacheName).then(function(t){return fetch(n,{credentials:"include",redirect:"follow"}).then(function(e){return t.put(n,e)})}))),t.respondWith(fetch(t.request).catch(function(e){return caches.open(cacheName).then(function(e){return e.match(t.request).then(function(e){return e&&404!=e.status?e:Promise.reject("no-match")})})}))}); -//# sourceMappingURL=sw.min.js.map +var cacheName="noushevr.github.io-offline-v1548146419";self.addEventListener("install",function(e){var t=new Request("index.html");e.waitUntil(fetch(t).then(function(n){return caches.open(cacheName).then(function(e){return console.log("[sw.js] Cached index page during install: "+n.url),e.put(t,n)})}))}),self.addEventListener("fetch",function(n){var t;n.waitUntil((t=n.request,caches.open(cacheName).then(function(n){return fetch(t,{credentials:"include",redirect:"follow"}).then(function(e){return console.log("[sw.js] Add page to offline: "+e.url),n.put(t,e)})}))),"only-if-cached"===n.request.cache&&"same-origin"!==n.request.mode||n.respondWith(fetch(n.request).catch(function(e){return console.log("[sw.js] Network request Failed. Serving content from cache: "+e),caches.open(cacheName).then(function(e){return e.match(n.request).then(function(e){return e&&404!=e.status?e:Promise.reject("no-match")})})}))}); \ No newline at end of file