问题
I am new to web push notification area. I want to send firebase web notifications from web to web. I tried doing that and ended up with this error
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration)
I dont know where am I went wrong. Thanks in Advance
回答1:
You need to add the service worker file firebase-messaging-sw.js
to the location where your files are served. This is the service worker firebase looks for.
Also, you need to share code with examples of what you are doing. No one is going to write your code from scratch.
回答2:
Finally got the answer.
We need to copy firebase-messaging-sw.js file and save it in the root of the folder. Since I used xampp, I ve push my push folder inside htdocs folder (/xampp/htdocs/push/), but you need to make sure that the firebase-messaging-sw.js should be in the root of the localhost(/xampp/htdocs/). i.e, when you search localhost/firebase-messaging-sw.js in browser, you shouldn't get a 404 error.
来源:https://stackoverflow.com/questions/52784051/firebase-web-push-notification-service-worker-issue