quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

FirebaseError: messaging/failed-serviceworker-registration

Open thinhdd13 opened this issue 10 years ago • 45 comments

Hi,

I got below error. Please help

Requesting permission... /quicks...saging/ (line 218) Notification permission granted. /quicks...saging/ (line 222) An error occurred while retrieving token. FirebaseError: Messaging: We are unable to register the default service worker. ServiceWorker script at http://localhost:8080/firebase-messaging-sw.js for scope http://localhost:8080/firebase-cloud-messaging-push-scope encountered an error during installation. (messaging/failed-serviceworker-registration). { code="messaging/failed-serviceworker-registration", message="Messaging: We are unable...ceworker-registration).", name="FirebaseError", more...}

Thanks and Regards, Ben

thinhdd13 avatar Nov 14 '16 01:11 thinhdd13

If you open a new tab for and add the following URL, does anything show up?

http://localhost:8080/firebase-messaging-sw.js

gauntface avatar Nov 15 '16 18:11 gauntface

i've inlcuded firebase-messaging-sw.js but the error it's equal to past . In principal script when include firebse-sw.file ?

Arkango avatar Jan 03 '17 10:01 Arkango

you shouldn't be including the service worker file anywhere. The SDK will register it when needed.

That error generally means that the file can't be found at the root of the origin.

So if you enter in http://localhost:8080/firebase-messaging-sw.js into a browser, does it return the file or does it show an error page?

gauntface avatar Jan 03 '17 21:01 gauntface

Its Return JS file content not giving error!! I had Put all the content on my server still i get these error ? Does anyone have found solution?

acharyajay007 avatar Jan 09 '17 17:01 acharyajay007

If you can provide an example repo or site that is showing it not working that would be helpful.

gauntface avatar Jan 24 '17 15:01 gauntface

http://localhost:8080/firebase-messaging-sw.js. I am getting page not found error for this. Can you help?

vaijan1990 avatar Jan 26 '17 04:01 vaijan1990

@vaijan1990 are you starting your server at the root or this repository or are you starting you server inside the messaging/ folder? It needs to be the latter.

gauntface avatar Jan 26 '17 15:01 gauntface

Yes. Thanks. It works now.

vaijan1990 avatar Jan 27 '17 06:01 vaijan1990

@gauntface im getting the same error.. whn i navigate to localhost:8080/firebase-messaging-sw.js is not found. and i placed it in root of my project.

emjimadhu avatar Mar 04 '17 08:03 emjimadhu

@emjimadhu just make it so that your server setup allows '/firebase-messaging-sw.js'

Without more information - extremely difficult to help you.

gauntface avatar Mar 06 '17 18:03 gauntface

@gauntface ok sorry for that.. here is the detail.. im using VueJS as my front end and my folder structure is like below..

webApp ..| - build
..| - config
..| - node_modules
..|| - src
........|| - assets
........|| - components
........|| - pages
........|| - app.vue ........|| - main.js ..| - index.html ..| - firebase-messaging-sw.js <= here is my actual service worker

so when i run my application, i get log stating that my service worker is not found.. in this folder structure where i have to place the service worker?

thank you in advance.

untitled

emjimadhu avatar Mar 07 '17 07:03 emjimadhu

@emjimadhu This is how you should debug this:

  1. Start your server
  2. Load you web page in a browser
  3. In your browser change your url to access the firebase-messaging-sw.js file (i.e. http://localhost:8080/firebase-messaging-sw.js - replacing the port etc).
  4. Notice that the file is not being served (I imagine your server redirects to index.html since it's a single page app).
  5. Debug how you would serve that file from the expect location. In this case, I imagine you need to put it in that static directory, or perhaps there is a way to configure your server not to redirect your URL.

gauntface avatar Mar 07 '17 15:03 gauntface

Hi, I'm using the vuejs webpack template and am having the same problem. I put the firebase-messaging-sw.js into do the dist folder and got it uploaded to firebase hosting as it worked. But in the dev environment it does not work. I guess it's because of the file not getting served in the local web server and that due the the complex setup with webpack and hot reloading and all.

scharinger avatar Mar 16 '17 22:03 scharinger

Hello, I am trying to use push-notification on Django Python website... I have created App on FCM, followed the instruction... I used JavaScript CDN... Now I am getting the following error while trying push-notification in my project

GET http://localhost:8080/firebase-messaging-sw.js net::ERR_INVALID_RESPONSE An error occurred while retrieving token. e {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…t. (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP res…code (404) was received when fetching the script."}

firebase-messaging-sw.js this file and .html file both are in same directory

When I tried http://localhost:8080/firebase-messaging-sw.js this in url I got Page not found (404) Please can help me to figure out... What I have done wrong....?

Thank You In Advance...

shreejayp95 avatar Jun 24 '17 12:06 shreejayp95

@shreejayp95 you must fix the issue 'http://localhost:8080/firebase-messaging-sw.js' OR use the useServiceWorker() function to pass in a custom service worker registration: https://firebase.google.com/docs/reference/js/firebase.messaging.Messaging#useServiceWorker

gauntface avatar Jun 27 '17 14:06 gauntface

If you are using Vue.js and Webpack and have problems in dev mode, just try to firebase serve. this worked for me

whoekage avatar Nov 19 '17 01:11 whoekage

Hi All,

Where do i get this file from? I get this after npm install on new project.

image

this file is not available in my project folder.

Thank you.

ghost avatar Nov 28 '17 18:11 ghost

@chanakyanet you need to create the file in your project.

Example: https://github.com/firebase/quickstart-js/blob/master/messaging/firebase-messaging-sw.js

gauntface avatar Nov 29 '17 17:11 gauntface

@sharkaev , could you please elaborate on how you solved it? I am facing similar situation.

iamsayantan avatar Dec 10 '17 16:12 iamsayantan

2017-12-14 17 30 20

Stop firebase-messaging-sw.js service worker. Maybe you activated it on another project.

tiepviet avatar Dec 14 '17 08:12 tiepviet