Reputation: 93
I'm facing a weird behaviour coming from inactive Chrome tabs.
I send notifications to my website, using jquery toastr and nodejs.
When a notification arrived I play a sound using this code :
new Audio("notif.mp3").play();
The notification is not displayed on a tab which is inactive since a while (sleep / hibernate, I'm not sure the exact terminology). That's understandable.
My problem is when I come back to the tab, the notification are not displayed (which is fine, they are too old anyway), but all the sounds are being played. So if you missed 100 notifications, you will hear 100 times "ding".
Any idea how to prevent/solve this ?
Upvotes: 1
Views: 1353
Reputation: 74
You could use : https://www.w3schools.com/tags/av_event_canplay.asp to know if can play the sound when the notification happens
Upvotes: 1