Closed Bug 1466500 Opened 6 years ago Closed 5 years ago

WebAudio context resumes unconditionally

Categories

(Core :: Web Audio, defect, P2)

61 Branch
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: zephiris, Assigned: padenot)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Build ID: 20100101

Steps to reproduce:

I found several webpages that were using audioContext.resume() on every webpage click to work around Chrome's auto-play audio block.


Actual results:

WebAudio's context resumed unconditionally. Websites took so much time resuming the audio context that firefox lost an overwhelming majority of click events.


Expected results:

WebAudio's context, as specified in https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-resume must abort further action if the context is already running. According to Firefox source code, it is unconditionally resumed.
Component: Untriaged → Web Audio
Product: Firefox → Core
Thanks for filing! I don't think we had such abuse in mind when we implemented the api. It sounds like a potential issue indeed.

Paul, can you check this when you have time?

Kirjah, do you have an example of such a website so we have something to confirm a fix with?
Flags: needinfo?(zephiris)
Flags: needinfo?(padenot)
Status: UNCONFIRMED → NEW
Rank: 19
Ever confirmed: true
Priority: -- → P2
Assignee: nobody → padenot
Flags: needinfo?(padenot)
https://treeherder.mozilla.org/#/jobs?repo=try&revision=8b17e549877080af6f3efd580630f7b4ce9677c6

Looks green on try. I had a to adjust a test as well, that was relying on the old behaviour.

I think this can make some code simpler. I had a look, and Chrome implements this more or less correctly (they return early). More or less, because they don't actually wait for the audio to be flowing before resolving `resume`, but I _think_ with this patch we should be more compatible.
Link to the standard: https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-resume (similar for suspend).
I think it should be possible to write a test for this, to make sure that the thenable for, for example, a `resume()` Promise is called exactly on the next microtask checkpoint if the context is already running, but we need to be able to reliably send an normal event loop task, and make sure the event queue is empty prior to sending the event and resolving the promise. I'll think about it.
I filed an issue re the specified behavior: https://github.com/WebAudio/web-audio-api/issues/1674

We don't understand why very slightly delayed promise resolution would cause loss of click events.

We need more information about why this is causing problems before changing the behavior.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Comment on attachment 8984905 [details]
Bug 1466500 - Update AudioContext.{suspend, resume} to match the spec.

https://reviewboard.mozilla.org/r/250676/#review257530

Returning early would leave the rendering suspended if the context had recently
been suspended, which would be inconsistent with Chrome's behaviour.

Perhaps it would be possible to resolve immediately in some situations, but
https://bugzilla.mozilla.org/show_bug.cgi?id=1269741#c6 seems to indicate this
would be complicated.
Attachment #8984905 - Flags: review?(karlt) → review-
Status: RESOLVED → REOPENED
Resolution: FIXED → ---

The spec has been changed to unconditionally try to resume, this is now invalid. Please file another, more focused bug if there still is a problem with Gecko's implementation.

Status: REOPENED → RESOLVED
Closed: 6 years ago5 years ago
Flags: needinfo?(zephiris)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: