Preventing multiple web notifications?

2.5k views Asked by At

I'm using websocket to receive notifications from server side, when I got a notification, I show a desktop notification using the Web Notification API, the problem is, if I'm opening this page in multiple tabs, I'd receive multiple duplicated desktop notifications...

I've tried to use cookies to store a flag, say when tab1 get the notification, it set a flag in the cookie, when tab2 get the same notification, it checks for the cookie flag, if there is one, tab2 wouldn't show a desktop notification. Sounds nice right? but it doesn't work, maybe tab1 and tab2 receive the notification from websocket so synchronous that the cookie is not set yet?

1

There are 1 answers

0
davidpaquipalla On

I suppose you get just datas from websocket, you can create a notification IF cookie say yes ELSE just ignore...