LorisBachert
LorisBachert

Reputation: 321

Not showing notifications when receiving a push event when the PWA is opened

This is a best practice question regarding the handling of push notifications in Pogressive Web Apps.

I'm currently developing a web app which contains a chat functionality. I added push notifications so the user gets a notification (via the NotificationsAPI) every time he receives a new chat message. This works fine. But receiving tons of push notifications even though the user has the chat window open is not a good user experience. Therefore i'd like to not show a notification at all if the user has the app open.

I know that not notifying the user about an incoming push is a critical topic and e.g. Chrome wants me to specify the userVisibleOnly flag. Is this a valid exception for not showing a notification or do you think i really need to show a notification every time a push is incoming? And if so, how can i deal with my problem? Anyone has any ideas how other apps are solving this issue?

Upvotes: 2

Views: 1606

Answers (1)

LorisBachert
LorisBachert

Reputation: 321

Addition: I may found the answer in one of Chromiums published documents: https://docs.google.com/document/d/13VxFdLJbMwxHrvnpDm8RXnU41W2ZlcP0mdWWe9zXQT8/edit#

"Each time a service worker finishes processing a push message but no notification from this origin is currently visible and there is no open and visible page on this origin, we check whether any of the past 10 push messages received from this origin also didn’t leave a notification on display (and didn’t have a page from the origin open and visible). If that is the case then we display a notification on the sites behalf so they user can understand that it ran.

[...]

*: (as well as being same-origin, it must be from the same browser profile; it isn’t however required to have loaded successfully, i.e. error pages count, as long as omnibox is showing the correct domain)."

As far as i understand it is allowed to not display notifications when the app is opened on the same device.

Upvotes: 1

Related Questions