Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

(service-worker.js) 'only-if-cached' can be set only with 'same-origin' mode #34

Closed
thgh opened this issue Feb 6, 2018 · 4 comments
Closed

Comments

@thgh
Copy link
Contributor

thgh commented Feb 6, 2018

Chrome devtools on https://svelte.technology/guide

The FetchEvent for "https://svelte.technology/guide" resulted in a network error response: the promise was rejected.
Promise.catch (async)
self.addEventListener.event @ service-worker.js:45
service-worker.js:52 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode
@poshaughnessy
Copy link

I think @wisdom-yzh is right and it should be only-if-cached, not only-if-cache ?

https://github.com/sveltejs/sapper-template/blob/master/app/service-worker.js#L69

@poshaughnessy
Copy link

I tried changing it to only-if-cached to see if that fixed the error for me. It did, but I got a different error now! :D It says "Cannot assign to read only property mode" - pointing to the line where it sets event.request.mode = "same-origin":

screenshot from 2018-06-29 17-19-52
screenshot from 2018-06-29 17-19-32

Sorry for commenting on a closed issue - would you like me to raise a new one?

@farhaan008
Copy link

Facing the same issue

@thgh
Copy link
Contributor Author

thgh commented Jun 30, 2019

@farhaan008 Here is a solution:

if (event.request.cache === 'only-if-cached') return;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants