I have been trying to customise notification message in front end, i.e if a field is not set send in notification, I am trying to add it.
importScripts('https://www.gstatic.com/firebasejs/5.0.4/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.0.4/firebase-messaging.js');
var config = {
apiKey: "x",
authDomain: "y",
databaseURL: "z",
projectId: "a",
storageBucket: "b",
messagingSenderId: "1"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
console.log('came here');
console.log(messaging.bgMessageHandler);
console.log(messaging.setBackgroundMessageHandler,'dsafdsadasfd')
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'
};
console.log(notificationOptions)
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
console.log(messaging.bgMessageHandler);
while executing the above code, I am not getting an console of [firebase-messaging-sw.js] Received background message ', payload
, even though i am getting notification.
Why is the setBackgroundMessageHandler
not working?