Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase messaging "the site has been updated in background"

I've got a problem. When getting a notification in my service worker:

messaging.setBackgroundMessageHandler(function(payload) {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);
  angularClient.postMessage(payload.data);
});

How can I prevent the browser from showing notification that says:

the site has been updated in background

What I do is sending a message to my service where the notification will be showed. For now it shows two notifications. One from my service which is fine and another saying "the site... ".

like image 497
standy Avatar asked Jan 26 '17 11:01

standy


2 Answers

You MUST show a notification when onBackgroundMessage is called and make sure your return the promise from registration.showNotification('title', {body: 'message'})

The reason for this is that web push doesn't support silent messages.

like image 99
Matt Gaunt Avatar answered Nov 09 '22 23:11

Matt Gaunt


I was getting this notification in addition to the one I created myself. Spent two days trying to fix it. This is the code that worked for me:

self.addEventListener('push', async function(event) {
    event.waitUntil(
        self.registration.showNotification('title', {
          body: 'body'
        })
    );
});
like image 23
ulu Avatar answered Nov 09 '22 23:11

ulu