Chrome Push Notification: This site has been updated in the background
I was expriencing the same issue but after a long research I got to know that this is because delay happen between PUSH event and self.registration.showNotification(). I only missed return keyword before self.registration.showNotification()
So you need to implement following code structure to get notification:
var APILINK = "https://xxxx.com"; self.addEventListener('push', function(event) { event.waitUntil( fetch(APILINK).then(function(response) { return response.json().then(function(data) { console.log(data); var title = data.title; var body = data.message; var icon = data.image; var tag = 'temp-tag'; var urlOpen = data.URL; return self.registration.showNotification(title, { body: body, icon: icon, tag: tag }) }); }) ); });
I've run into this issue in the past. In my experience the cause is generally one of three issues:
- You're not showing a notification in response to the pushmessage. Every time you receive a push message on the device, whenyou finish handling the event a notification must be left visible onthe device. This is due to subscribing with the
userVisibleOnly:true
option (although note this is not optional, and not setting itwill cause the subscription to fail. - You're not calling
event.waitUntil()
in response to handling the event. A promise should be passed into this function to indicate to the browser that it should wait for the promise to resolve before checking whether a notification is left showing. - For some reason you're resolving the promise passed to
event.waitUntil
before a notification has been shown. Note thatself.registration.showNotification
is a promise and async so you should be sure it has resolved before the promise passed toevent.waitUntil
resolves.
Generally as soon as you receive a push message from GCM (Google Cloud Messaging) you have to show a push notification in the browser. This is mentioned on the 3rd point in here:
So it might happen that somehow you are skipping the push notification though you got a push message from GCM and you are getting a push notification with some default message like "This site has been updated in the background".