我正在研究Firebase FCM推送通知的角度项目。当我在Chrome中打开我的项目标签时,我从服务器收到消息,但是当我的标签不清晰时(即其他某个标签打开),我就没有收到消息。
I implemented FCM notification in which i recieve notification(on desktop widow)and data(which is displayed on web window) from server after every minute. When my project localhost window is opened then i recieve data, but now i want to catch that data even when my localhost window is not open.
I used the following code provided by FCM
https://github.com/firebase/quickstart-js/blob/master/messaging/firebase-messaging-sw.js
but it does not work
my firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-messaging.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
var messaging = firebase.messaging();
firebase.initializeApp({
'messagingSenderId': '232325831223'
});
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
var notificationTitle = 'Background Message Title';
var notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
i want to recieve data message even when my window is closed or somehow capture the message sent by server in firebase so that whenever i open my localhost tab then i recieve that message