setbackgroundmessagehandler does not show the message in chrome
Hi,
importScripts('https://www.gstatic.com/firebasejs/6.3.4/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/6.3.4/firebase-messaging.js');
firebase.initializeApp({
apiKey: "xxxxxxxxxxxx",
authDomain: "xxxxxxxxxxxx",
databaseURL: "https://xxxxxxxxxxxx",
projectId: "xxxxxxxxxxxx",
storageBucket: "",
messagingSenderId: "xxxxxxxxxxxx",
appId: "xxxxxxxxxxxx"
})
/*
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);
const notification = JSON.parse(payload.data.notification);
// Customize notification here
const notificationTitle = notification.title;
const notificationOptions = {
body: notification.body,
icon: notification.icon
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
Payload:
{
"data":{
"notification": {
"title": "Firebase",
"body": "test",
"click_action": "http://xxxxx",
"icon": "icon.png"
}},
"to": "/topics/all"
}
performing debugger, the payload data arrives at the setBackgroundMessageHandler method, when arriving at the self.registration.showNotification does not show the popup message window, and the console does not mark error, chrome desktop Versión 77.0.3865.90 (Build oficial) (64 bits) In mozilla if it shows the popup message
what could be happening?
regards
I got the same issue in both chrome and firefox
Ok so assuming this is your SW?
Your initialization for firebase is wrong. it must simple be:
firebase.initializeApp({
'messagingSenderId': '<Your actual sender id>'
});
Same issue. in both chrome, firefox and mobile chrome browser. If the tab is not focussed it still shows in console "Handling background message" so in short its going to backgroundeventhandler but not opening any pop up window..
Ok so assuming this is your SW?
Your initialization for firebase is wrong. it must simple be:
firebase.initializeApp({ 'messagingSenderId': '<Your actual sender id>' });
I got the same issue in both chrome and firefox
hi r u able to resolve this
Ok so assuming this is your SW? Your initialization for firebase is wrong. it must simple be:
firebase.initializeApp({ 'messagingSenderId': '<Your actual sender id>' });I got the same issue in both chrome and firefox
hi r u able to resolve this
not yet
notification type messages are handled automatically by the FCM SDK, and are not made available to setBackgroundMessageHandler. This is documented here.