Closed pablogravielseo closed 4 years ago
Do you have any custom service worker code? This error would indicate a runtime error at registration. Also - what browser?
Hi @eshtadc yes I have, I use Opera and Chrome.
In development environment I've got the correct file of sw.js
, but in staging and production environment I don't know why I'm getting the content of "index.html" file from the sw.js
file
This seems to be what is causing the JS error and therefore the runtime error. I verified at your login page.
Maybe it is the way things are deployed. Your other JS assets appear to be coming from cloudfront.net rather than the herokuapp where the sw.js is trying to load from. Where is your sw.js file?
@eshtadc yesterday I realised about this, I'm using "ember-cli-deploy" I'm trying to figuring out where is the sw.js
in staging environment. A question, the addon generates dynamically a sw.js
file in the current root path right? There is a way to manually change the path?
@eshtadc my co worker found the file, is on S3 now we are finding a way to set the correct path.
Glad you found it. Keep in mind that afaik service workers must be on the same origin. https://w3c.github.io/ServiceWorker/#origin-relativity https://github.com/DockYard/ember-service-worker/issues/97
@eshtadc sorry, is it possible to remove the links that I shared from you last message? I didn't know that I needed to maintain privately.
Message updated :)
@eshtadc thank you! :)
@eshtadc is possible: https://github.com/DockYard/ember-service-worker/issues/154#issuecomment-518654969?
Yes - it is possible to load from a different path on the same domain. You can pass rootUrl
in your configuration.
For example in ember-cli-build.js
if you are planning to have your sw.js
in a myrootfolder
directory:
var app = new EmberApp(defaults, {
'ember-service-worker': {
rootUrl: ''/myrootfolder/"
}
});
Does this help?
yes helps thank you, and it's possible to set the path of the sw.js
file to decide where will be served? or just doing the configuration you had mentioned above the app will serve in that path?
ember-service-worker currently always generates the file in the root in order to allow access to the full project. See https://developers.google.com/web/fundamentals/primers/service-workers/#register_a_service_worker
I believe the case that the rootUrl
configuration above was created for was someone who had a deployment system that moved files around during deployment and therefore needed the registration to load from a custom location. It's a non-standard option (and that's why its left out of the docs).
I'm closing this issue due to inactivity but please comment if you feel that's not correct and we can re-open and continue the conversation.
Hello when I use the service worker locally works normally, but when the app is deployed I get this error message on the console:
Service Worker registration failed with TypeError: Failed to register a ServiceWorker: ServiceWorker script evaluation failed
Someone had faced something similar??
I'm using:
Ember service worker and plugins version: