Answer the question
In order to leave comments, you need to log in
How to get rid of double push?
The site uses firebase notifications. When the pwa app on the phone is in the foreground, everything is fine, pushes come in, but if in the background, then two of them arrive at once. As it turned out, this is due to event handling in the service worker:
// firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: 'ххххххххххххх'
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
// return self.registration.hideNotification();
});
self.addEventListener('push', event => {
let payload = event.data.json();
let options = payload.notification;
options.data = {};
options.data.url = options.click_action;
let title = options.title;
event.waitUntil(Promise.all([self.registration.showNotification(title, options)]));
});
messaging.onMessage(function(payload) {
...............
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question