Monday, May 20, 2024
89
rated 0 times [  94] [ 5]  / answers: 1 / hits: 19186  / 6 Years ago, fri, january 26, 2018, 12:00:00

After upgrading to Chrome 64, I realized that this error appears when I load my page on a new tab.



enter



I can't identify where it is on the service worker. Here is my code to run the fetch:



self.addEventListener('fetch', function(event) {
if (event.request.url.startsWith(self.location.origin)) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request).then(function(fetch_resp){
return fetch_resp;
});
})
);
}
});


Could anyone here, who has more knowledge about service worker, help me to solve this error?


More From » service-worker

 Answers
70

I believe this is a Chromium bug that has been reported here. Hopefully it will be fixed soon or some more information about the issue will be published.



Paul Irish implemented a temporary work around, which is as follows:



if (e.request.cache === 'only-if-cached' && e.request.mode !== 'same-origin') {
return;
}


I ran it inside the callback for the service worker install and fetch listeners and it prevented the error.



You can see the full commit of Paul's code here.


[#55348] Wednesday, January 24, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
halleyb

Total Points: 604
Total Questions: 96
Total Answers: 115

Location: Tokelau
Member since Wed, Oct 14, 2020
4 Years ago
;