2

This is pretty insane. I've built a VueJS based frontend for an order recieving application. Technically I'm making an ajax call every two minutes to check for orders. If there are any orders I have it play a sound. This I've implemented by calling play on an hTML audio element.

The problem is that if the browser tab is not focused or if the user is on another tab. The sound doesn't play. I've even changed the code to instead of playing a sound file - refresh a hidden iframe that loaded the sound file. But that also doesn't seem to work if the browser is out of focus. What exactly am I missing here.

-- EDIT

My situation is that - the user would have multiple browser tabs open and the only way to alert the user would be via a unique sound that would be played. I know it can be done because there are a number of other sites that do this somehow. I'm not sure how. Is there a way to force focus back to the tab using javascript?

Ali
  • 7,353
  • 20
  • 103
  • 161
  • Possible duplicate of [HTML5 audio tag not playing sound for the very first of unfocused tab in chrome and safari?](https://stackoverflow.com/questions/36562529/html5-audio-tag-not-playing-sound-for-the-very-first-of-unfocused-tab-in-chrome) – jmargolisvt Apr 03 '19 at 17:24
  • I know you used to be able to get around this in chrome by playing a blank sound as soon as the tab was initially loaded, not sure if that still works – WilliamNHarvey Apr 03 '19 at 17:25
  • Interesting - is this then specific to Chrome? The thing is that orders come in randomly and I would want a way to issue some kind of audio alert somehow. – Ali Apr 03 '19 at 17:55
  • I have the same problem here, and would be interested with a possible solution. Thanks. – Cédric VIDREQUIN Jun 24 '20 at 07:46
  • I know this is a bit old, but if a [mcve] could be shared, preferably with a list of browser brands and versions, that'd make it possible to debug the issue. Until then, [Playing sound from INACTIVE browser tab](https://stackoverflow.com/questions/33196475/playing-sound-from-inactive-browser-tab?rq=2) seems canonical. – ggorlen Mar 21 '23 at 19:13

0 Answers0