I am getting notifications twice when the application in the background. Here is my Service-worker file. When we call this firebase.messaging() function, the service-worker starts receiving and displaying push notifications automatically. Service-worker is showing both notifications. one initializing by the firebase and one with this code self.registration.showNotification(notificationTitle, notificationOptions).
importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-messaging.js');
// Initialize the Firebase app in the service worker by passing in
firebase.initializeApp({
apiKey: "apiKey",
authDomain: "authDomain",
projectId: "projectId",
storageBucket: "storageBucket",
messagingSenderId: "messagingSenderId",
appId: "appId"
});
const messaging = firebase.messaging();
messaging.onBackgroundMessage( function(payload){
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: 'Testing',
};
return self.registration.showNotification(notificationTitle, notificationOptions);
});
How to prevent default notification?