Monday, May 20, 2024
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 128111  / 9 Years ago, tue, may 19, 2015, 12:00:00

I get this error when trying to register the service worker:




Failed to register a ServiceWorker: A bad HTTP response code (404) was gwreceived when fetching the script.




I'm working with ionic and this is what I have in the app.js:



   if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
//registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}else {
console.log('No service-worker on this browser');
}


On the directory I have the service-worker.js file right next to the app.js on the same folder.



Using latest chrome version on ubuntu desktop.


More From » service-worker

 Answers
99

You mention that you have service-worker.js in the same directory as app.js, but the URL passed to .register() is relative to the HTML document's path. You need to make sure your service-worker.js file is in the same directory as the .html file corresponding to the page you're on.


[#66535] Monday, May 18, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;