Users reported a bug on the hosted Discourse site where enabling desktop notifications in Chrome results in duplicate alerts for a single reply when multiple tabs are open jsha. While jomaxro initially suspected a Chrome issue, tgxworld clarified it was a Discourse bug caused by each open tab subscribing to the messagebus and triggering its own notification. The team discussed using notification tags to group alerts and the potential of service workers for a long-term fix. riking noted that auto-clearing notifications after 10 seconds also caused issues for users in fullscreen mode. tgxworld explained that a previous fix using localStorage to restrict notifications to the primary tab had been broken by internal changes. A pull request was submitted to restore the primary tab check, resolving the duplicate notification issue tgxworld, which jsha confirmed as an excellent fix.
I don’t remember this happening at first.. but couldn’t say if it was a new version of Chrome or Discourse that made me see multiple notifications frequently.
I would actually classify it as a Discourse bug because we’re the ones triggering two notifications. Each open tab subscribes to a messagebus callback that creates a new notification. Therefore, two open tabs equals two notifications created.
Right now, we’re assigning tags to each notification but all it does is replace the notification that has the same tag which is why we’re seeing the behavior here.
Notification: tag property - Web APIs | MDN
The idea of notification tags is that more than one notification can share the same tag, linking them together. One notification can then be programmatically replaced with another to avoid the users’ screen being filled up with a huge number of similar notifications.
Using push notifications through service workers would fix/replace this but without support for a data payload in push yet, it is going to be tricky to implement correctly.
Oh right, another thing that should be done, in addition to what @tgxworld said, is to stop auto-clearing the notification after 10 seconds, as the browser now does that.
Clearing it after 10 seconds causes problems if, e.g. you are watching a full-screen video, where normally notifications are delayed until you exit fullscreen.
Ah ok. Actually the implementation by @riking had a check for the primary tab. So even though we have two tabs open, it’ll only trigger notifications on the “active” tab by setting the values in localStorage. We made some internal changes that broke it