Firebase web push notification Service worker issue

孤者浪人 提交于 2020-07-20 04:15:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!