New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 747616 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner: ----
Closed: Jun 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug

Blocked on:
issue 715049



Sign in to add a comment

Cannot play audio notifications in response to websocket / xhr requests

Reported by tom.wilt...@gmail.com, Jul 21 2017

Issue description

UserAgent: 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?
 
audio_test.html
582 bytes View Download
Cc: animohan@chromium.org owe...@chromium.org ojan@chromium.org
[+ owencm for notifications, ojan ani for intervention-y behavior]
Cc: mlamouri@chromium.org dah...@chromium.org dalecur...@chromium.org
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)
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.
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?


Labels: Needs-Milestone
Status: Untriaged (was: Unconfirmed)
Blockedon: 715049
Status: Available (was: Untriaged)
Components: Blink>Media>Autoplay

Comment 9 by ojan@chromium.org, May 8 2018

Cc: -ojan@chromium.org
Labels: -Needs-Milestone
Status: Fixed (was: Available)
Per mlamouri this is fixed with new autoplay policy launch.

Tom, please re-open if this is still an issue
Thanks y'all!

Sign in to add a comment