Closed Bug 1828989 Opened 2 years ago Closed 2 years ago

Don't display autoplay warning on construction of AudioContext

Categories

(Core :: Web Audio, defect)

Firefox 110
x86_64
Linux
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: ciwit31509, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0

Steps to reproduce:

Create AudioContext in a global scope (to use later with a user gesture).

Actual results:

I get the console warning "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page."

It is not wrong to create AudioContext outside a user gesture, so unless you are attempting to autoplay there is no reason for the warning.

Same as:
https://bugs.chromium.org/p/chromium/issues/detail?id=943258&q=warning%20audiocontext%20user%20gesture&can=1

Expected results:

No warning should display

Component: Untriaged → Web Audio
OS: Unspecified → Linux
Product: Firefox → Core
Hardware: Unspecified → x86_64
Severity: -- → S4

flyby, would it be possible to provide a test page to try and reproduce this issue on my side? Thanks

Flags: needinfo?(ciwit31509)

Uploaded test page gives the console warning:

"An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page."

There is no attempt made to start the audioContext automatically.

I've loaded the test page in both Chrome and Nightly on Windows 10x64, and following warning message is displayed in Console:
Google Chrome: The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
Nightly 115.0a1: An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page.

Setting this as NEW in order to involve the development team and get an opinion on this.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Per specification, an AudioContext starts automatically, but browsers can (and do) block this from happening except when users have interacted with the page, or users allow auto-play.

There is no way to create an AudioContext that does not start automatically, because it was specified like this in 2011 and we can't change it now because it would break countless websites, so we block them from auto-playing and display a message for authors to help debugging. This can be perceived as annoying, but it's better than the alternatives. Maybe in a few years we'll be able to remove those messages.

Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(ciwit31509)
Resolution: --- → INVALID

Ok, it may not the most important thing. But you normally would not create the AudioContect in the user gesture as you create it one time to use and then reuse, create it anew every time would be unnecessary and perhaps even mess up the timing and so on. So in reality you always get this warning and by that it fills no purpose. Or you have to write code specifically to NOT get the warning which is also not ideal.

My take is, the warning serves no purpose, and could potentially inspire web developers to write worse code to not see it in the console every time you debug. And I vote for you to follow chromium example in this matter where they have decided to warn only when autoplay is attempted (see chrome issue first post comment 11 and 12).

Thank you

MDN:
It's recommended to create one AudioContext and reuse it instead of initializing a new one each time, and it's OK to use a single AudioContext for several different audio sources and pipeline concurrently.

https://developer.mozilla.org/en-US/search?q=audiocontext

@comment 4: According to the specs (todays date) AudioContext should start in suspended mode, and if "allowed to start" be set to running. So the AudioContext would not not be started atomatically if not allowed.

Yes, but this is a breaking change. It has changed recently (a small number of years), it used to always start automatically. Because this is a breaking change, we have a warning in the console so that developers understand why this is happening.

Besides, on other browsers than Firefox on some websites, and on Firefox if you have configured it to do so, it will automatically transition to "running" without user action.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: