Answer the question
In order to leave comments, you need to log in
How to run Firebase 9?
Now working with firebase 8 file firebase-messaging-sw.js
importScripts("https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js");
// https://firebase.google.com/docs/web/learn-more
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
let options = {
body: payload.data.body,
icon: payload.data.icon
}
let user = localStorage.getItem('VAFUserId'),
data = JSON.parse(payload.data['gcm.notification.data']);
// Search by hash
if(data.users.find(el => el == user)) {
return self.registration.showNotification(payload.data.title, options);
}
});
// JavaScript Document
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.3/firebase-app.js';
import { getMessaging, onBackgroundMessage } from 'https://www.gstatic.com/firebasejs/9.1.3/firebase-messaging-sw.js';
const firebaseApp = initializeApp({
});
const messaging = getMessaging(firebaseApp);
onBackgroundMessage(messaging, (payload) => {
let options = {
body: payload.data.body,
icon: payload.data.icon
}
let user = localStorage.getItem('VAFUserId'),
data = JSON.parse(payload.data['gcm.notification.data']);
// Search by hash
if(data.users.find(el => el == user)) {
return self.registration.showNotification(payload.data.title, options);
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question