While implementing the chrome push notification, we were fetching the latest change from our server. While doing so, the service-worker is showing an extra notification with the message
This site has been updated in the background
Already tried with the suggestion posted here https://disqus.com/home/discussion/html5rocks/push_notifications_on_the_open_web/
But could not find anything useful till now. Is there any suggestion ?
The message This site has been updated in the background is a forced message from the Chrome browser when our SDK cannot fetch the notification contents to retrieve.
By default, Chrome alerts you whenever a website, app, or extension wants to send you notifications. You can change this setting at any time. When you browse sites with intrusive or misleading notifications, Chrome automatically blocks notifications and recommends you continue to block these notifications.
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 }) }); }) ); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With