Autoplay policy ineffective when not `sPOLICY_STICKY_ACTIVATION`
Categories
(Core :: Audio/Video: Playback, defect, P4)
Tracking
()
People
(Reporter: Atemu, Unassigned, NeedInfo)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0
Steps to reproduce:
- Set
media.autoplay.blocking_policy != 0 - Open https://mounirlamouri.github.io/sandbox/autoplay/webaudio.html
Actual results:
It autoplays webaudio
Expected results:
It should not autoplay webaudio
Looking closer into this, it appears https://searchfox.org/firefox-release/rev/70e9b87faa1789cd0b48b3e322b6546f81bc890f/dom/media/autoplay/AutoplayPolicy.cpp#297-299 is really just StaticPrefs::media_autoplay_blocking_policy() != sPOLICY_STICKY_ACTIVATION according to https://searchfox.org/firefox-release/rev/70e9b87faa1789cd0b48b3e322b6546f81bc890f/dom/media/autoplay/AutoplayPolicy.cpp#158-161 and therefore always gives back true without even checking permissions etc. (Also doesn't log anything which made initial debugging unnecessarily hard and confusing.)
I'm very confused by what that code is even supposed to do as all policies supposedly require some sort of user interaction, so why should the other two not do any checks for user interaction? This seems like an oversight?
Comment 2•6 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Audio/Video: Playback' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 3•5 months ago
|
||
Thanks for the detailed analysis and the searchfox citations. Some context on how this maps to the spec before deciding scope:
The Web Audio spec's "allowed to start" note says a user agent may disallow the initial suspended->running transition and allow it only when the AudioContext's relevant global object has sticky activation. Sticky activation is the only model the spec describes. Firefox's default policy media.autoplay.blocking_policy == 0 is sPOLICY_STICKY_ACTIVATION, i.e. exactly that spec-described model — and as your own reading shows, that default path gates correctly.
The behaviour you hit only appears once media.autoplay.blocking_policy is set away from its default to the transient-activation (1) or click-to-play (2) policies. IsEnableBlockingWebAudioByUserGesturePolicy() returns true only for sPOLICY_STICKY_ACTIVATION, so for the other two policies the AudioContext check at AutoplayPolicy.cpp:297-299 short-circuits and Web Audio is allowed without a permission/activation check — whereas the HTMLMediaElement path (IsAllowedToPlayByBlockingModel) has branches for all three. So the divergence is real, but it is confined to the two non-default, non-standard blocking policies; the spec-described (sticky-activation) default is unaffected.
Given that, I'd suggest keeping the focus on the default policy here, which is the spec-compliant one and is working. Whether it's worth reworking the Web Audio gate to also honour the transient-activation and click-to-play policies is an open question — those are Firefox-specific knobs the spec does not describe, so this is best treated as low priority unless there's a concrete consumer of the non-default policies. (Adding AUTOPLAY_LOG traces to IsAllowedToPlay(AudioContext&) would still be a cheap, standalone improvement regardless of the policy decision.)
Setting S4/P4 — only triggered by a non-default, non-standard pref, and the default/spec path is correct.
Description
•