我的代码在chrome(版本103.0.5060.134)上完美运行,但是当我在firefox(103.0)上尝试它时它不起作用。
Service Worker 注册成功,但无法接收通知/消息。控制台中没有显示错误
这是我的代码(顺便说一句,我正在使用 vue v2)
firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-app-compat.js')
importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-messaging-compat.js')
// Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
apiKey: 'api-key',
authDomain: 'project-id.firebaseapp.com',
databaseURL: 'https://project-id.firebaseio.com',
projectId: 'project-id',
storageBucket: 'project-id.appspot.com',
messagingSenderId: 'sender-id',
appId: 'app-id',
measurementId: 'G-measurement-id',
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
Run Code Online (Sandbox Code Playgroud)
注册ServiceWorker.js
import { register } from 'register-service-worker'
if (process.env.NODE_ENV === …Run Code Online (Sandbox Code Playgroud)