2

I implemented web push notifications. Steps to get a bug:

  1. Open website
  2. Subscribe for push notifications
  3. Send many pushes through gcm - all fine
  4. Close tab with site
  5. Send push and receive "double push" - first one is ok, second is "This site has been updated in background"
  6. Reopen website
  7. 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?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Dmitry Teplyakov
  • 2,898
  • 5
  • 26
  • 46
  • Can you clarify #5? Are you sending one push message but receiving two of them? Or just sending two push messages? – Miguel Garcia Nov 26 '15 at 12:37
  • Also is this on desktop or Android? – Miguel Garcia Nov 26 '15 at 12:38
  • @MiguelGarcia I tested it on desktop. #5 Sending one push message - receave two pushes. First is real, second is not. – Dmitry Teplyakov Mar 17 '16 at 22:35
  • I'm having a similar issue. I am returning a promise all the time. Maybe you can help me? http://stackoverflow.com/questions/35948633/how-to-prevent-chrome-background-notifications-from-showing-twice-when-adding-we – Ryan Ewen Mar 29 '16 at 02:53

1 Answers1

6
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', {});
          });
      });
  );
}
Dmitry Teplyakov
  • 2,898
  • 5
  • 26
  • 46
  • Thank you. I had this same issue, and was missing the return statement before the fetch call. – Aaron Apr 14 '16 at 01:47
  • That "answer" is poorly formatted. The questions: 1.) Why am I seeing strange notifications? **UNANSWERED** 2.) Can I get rid of such behavior? (How do I is implied) You have some code, but no indication of where it's from, how to get to it, what needs to be changed, how you found it, or even confirming that this *will* "get rid of such behavior". Please update the answer with the appropriate information. – LostOnTheLine Jan 09 '23 at 16:32