Cannot play audio notifications in response to websocket / xhr requests
Reported by
tom.wilt...@gmail.com,
Jul 21 2017
|
||||||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 Steps to reproduce the problem: The example page just issues an XHR in response to a button click, and plays audio when the XHR returns. To reproduce, click the button then very quickly change tabs. Wait a few seconds to convince yourself the audio isn't playing. Then switch back to the tab, and it'll play suddenly. This issue is present across a range of scenarios -- in our production web app its actually affecting notifications we try to play in response to websocket data, but that's harder to demonstrate. What is the expected behavior? The sound plays in the background. Or at minimum the browser blocks it and doesn't play it -- but it shouldn't suddenly play later! In our web app workers answer incoming calls. Sometimes they get a notification but the sound is delayed; they answer the call through other means and are on the phone but then when they switch tabs suddenly it rings! Distracting and bad. What went wrong? Audio plays only when switching back to the tab (neither blocked nor played on time). Did this work before? N/A Does this work in other browsers? N/A Chrome version: 59.0.3071.115 Channel: stable OS Version: OS X 10.12.5 Flash Version: I believe it's "working as intended" because the audio isn't being played in direct response to a user gesture. But I'm not sure what the "correct" way to deal with it is. The web is full of various hacky suggestions (eg https://stackoverflow.com/questions/35525968/autoplay-sound-in-chrome-background-tab/36166522 ) but none of them are very satisfying. We have a pretty straightforward need -- play an alert sound when an important thing happens in the background. We use desktop notifications for a visual alert, but need audio too. The desktop notification spec has an "audio" component, but it's currently unimplemented. In the mean time, what's the right way for developers to play notifications in response to server data in the background?
,
Jul 22 2017
This is indeed working as intended. The idea is that a tab isn't allowed to play in the background if it did not first play in the foreground. +dalecurtis@, given that I believe you implemented this, what would you think of reducing the restriction to only require the page to have been in the foreground instead of playing something in the foreground? I think that this would solve the "open in a new tab" annoyance for website that would have bene whitelisted with media engagement without adding more noise to our autoplay rules. WDYT? (+dahlke@ for autoplay)
,
Jul 24 2017
I think it's probably okay, but note that it might be surprising to users. Every user discussion around this yields positive feedback, though it's mostly aimed at the open-defers type usage.
,
Jul 24 2017
I totally get the desire to silence background tabs. Seems like a worthwhile feature that you might want to keep. The "only if audio was previously played in foreground" is what leads to the suggestion in that StackOverflow post: "The solution that worked for me was to play a small blank sound (0.1 second is enough) once the page is loaded. After that even if you switch to another tab, the tab in the background will still be able to play the sound on some external or internal event." I'll try implementing this on our site as a workaround. At which point I guess the question is, do we consider this the "right" solution for the platform? It seems, ah, rather kludgy. A few other options: - make this a permission, like showing notifications - say that the use case here is pretty narrowly notification alerts, and implement the "sound" components of the Notification API Regardless of the decision there, I do sort of question the "defer playing audio until the tab gains focus" behavior. It makes sense for the popunder case, but for apps that try and fail to play a sound its very surprising user behavior to suddenly get this audio playing out of context. Are web app authors meant to somehow detect that the sound was deferred and cancel playback? Is there a way to do that?
,
Jul 26 2017
,
Jul 27 2017
,
Oct 24 2017
,
Feb 8 2018
,
May 8 2018
,
Jun 11 2018
Per mlamouri this is fixed with new autoplay policy launch. Tom, please re-open if this is still an issue
,
Jun 13 2018
Thanks y'all! |
||||||||
►
Sign in to add a comment |
||||||||
Comment 1 by komoroske@chromium.org
, Jul 21 2017