如何解决FirebaseError:: 我们无法注册默认的 Service Worker
FirebaseError: Messaging: 我们无法注册默认的 Service Worker。无法使用脚本 ('http://127.0.0.1:8000/firebase-messaging-sw. js'):获取脚本时收到错误的 HTTP 响应代码 (404)。 (消息/失败的服务工作人员注册)。
PS:我在根文件夹中有 firebase-messaging-sw.js(即 /public )
firebase-messaging.js
/*
Give the service worker access to Firebase Messaging.
Note that you can only use Firebase Messaging here,other Firebase libraries are not available in the service worker.
*/
importScripts('https://www.gstatic.com/firebasejs/7.23.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.23.0/firebase-messaging.js');
/*
Initialize the Firebase app in the service worker by passing in the messagingSenderId.
* New configuration for app@pulseservice.com
*/
firebase.initializeApp({
apiKey: "XXXXXXXXXXXXXX",authDomain: "XXXXXXXXXX.firebaseapp.com",projectId: "XXXXXXXXXX",storageBucket: "XXXXXXXXXX.appspot.com",messagingSenderId: "XXXXXXXXXXXX",appId: "XXXXXXXXXXXXXXX"
});
/*
Retrieve an instance of Firebase Messaging so that it can handle background messages.
*/
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log(
"[firebase-messaging-sw.js] Received background message ",payload,);
// Customize notification here
const notificationTitle = "Background Message Title";
const notificationoptions = {
body: "Background Message body.",icon: "/itwonders-web-logo.png",};
return self.registration.showNotification(
notificationTitle,notificationoptions,);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。