I'm using Firebase Messaging for browser notifications. Problem is when multiple tabs are open. Notification for every tab is shown. Adding tag to options didn't help
firebase.initializeApp(constants.CONFIG);
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(({ data }) => {
const options = {
body: data.body,
data: { link: data.link, },
icon: data.icon,
};
const backgroundNotification = self.registration.showNotification(data.title, options);
return backgroundNotification;
});
I need only one notification to be displayed even when many tabs with same app are open
Comment this line of code
const backgroundNotification = self.registration.showNotification(data.title, options);
and use instead
new Notification(notification.title, {
body : notification.body,
tag : notification.title,
icon : notification.icon
});
Example 3.5: https://notifications.spec.whatwg.org/