I implemented web push notifications. Steps to get a bug:
- Open website
- Subscribe for push notifications
- Send many pushes through gcm - all fine
- Close tab with site
- Send push and receive "double push" - first one is ok, second is "This site has been updated in background"
- Reopen website
- Send push - all fine
I know this can happen when the service worker receives push and doesn't show notification. But I see normal notification, why I also see other strange notification? Can I get rid such behaviour?
self.addEventListener('push', function(event) {
// this function should return promise always
}
In my case:
self.addEventListener('push', function(event) {
event.waitUntil(
self.registration.pushManager.getSubscription()
.then(function(subscription) {
fetch('url')
.then(function(response) {
self.registration.showNotification('title', {});
});
});
);
}
should be:
self.addEventListener('push', function(event) {
event.waitUntil(
self.registration.pushManager.getSubscription()
.then(function(subscription) {
return fetch('url')
.then(function(response) {
return self.registration.showNotification('title', {});
});
});
);
}