Some notes on Firefox's current media autoplay settings

April 27, 2018

I am quite violently against videos ever auto-playing in my regular browser, under basically any circumstances ever (including ones like the videos that Twitter uses for those GIFs that people put in their tweets). I hate it with audio, I hate it without audio, I hate it on the web page I'm currently reading, I hate it on the web page in another tab. I just hate it.

I've traditionally used some number of extensions to control this behavior on prominent offenders like YouTube (in addition to setting various things to 'ask before activating'). When I wrote about my switch to Firefox Quantum, I said that I was experimenting with just turning off Firefox's media.autoplay.enabled preference and it seemed to work. I had to later downgrade that assessment and tinker with additional preferences, and I have finally dug into the code to look at things in more depth. So here are some notes.

First, there appear to be at least two circumstances when a video will request autoplaying. The usual case is when it's embedded in a web page and either its <video> element asks for it or some JavaScript runs that tries to start it. The second case is when at least some .mp4 files are directly loaded as standalone URLs (either in the current page or in a new tab), for example because someone just directly linked to one and you clicked on the link (yes, some people do this). As far as I can tell Firefox follows the same 'can it autoplay' checks for both cases.

The actual Firefox code that implements the autoplay policy checks is pretty short and sort of clear; it's the obvious function in AutoplayPolicy.cpp. As far as I can follow the various bits, it goes like this:

  • if media.autoplay.enabled is true (the default case), the autoplay is immediately allowed. If it's false, we don't reject it immediately; instead, we continue on to make further checks and may still allow autoplay. As a result, the preference is misnamed (likely for historical reasons) and should really be called something like media.autoplay.always_allow.

    (There is currently no Firefox preference that totally and unconditionally disables autoplay under all circumstances.)

  • Pages with WebRTC camera or microphone permissions are allowed to autoplay, presumably so that your video conferencing site works smoothly.

  • if media.autoplay.enabled.user-gestures-needed is false (the default), whether autoplay is allowed or forbidden is then based on the video element is 'blessed' or, I think, if the web page is the currently focused web page that's handling user input (ie, it's not hidden off in a tab or something). As far as blessing goes, the code comments for this say:

    True if user has called load(), seek() or element has started playing before. It's only use for checking autoplay policy[.]

  • if media.autoplay.enabled.user-gestures-needed is true, Firefox checks to see if the video will be playing without sound. If it will be silent, the video is allowed to autoplay, even if it is not in the current tab and you haven't activated it in any way.

    If the video has audio, it's allowed to autoplay if and only if the web page has been activated by what comments call 'specific user gestures', which I think means you clicking something on the web page or typed at it.

This means the behavior of silent videos is different based on whether or not you have m.a.e.user-gestures-needed set. If it's the default false, a silent video in another tab will not autoplay. If you've set it to true to get more control in general, you paradoxically get less control of silent videos; they'll always autoplay, even when they've been opened in another tab that you haven't switched over to yet.

(My current fix for this is to comment out the audio checking portion of that code in my own personal Firefox build, so that silent videos get no special allowances. A slightly better one might be to immediately deny autoplay if EventStateManager::IsHandlingUserInput() is false, then check audio volume; if I'm understanding the code right, this would allow silent video to autoplay only on the current page. Since I don't want videos to ever autoplay, I'm fine with my fix and I may someday try making the entire function just immediately return false.)

Turning off media.autoplay.enabled does cause a certain amount of glitches for me on YouTube, but so far nothing insurmountable; people have reported more problems with other sites (here is one explanation). The Mozilla people are apparently actively working on this area, per bug 1231886, which has quite a number of useful and informative comments (eg), and bug 1420389.

(As far as other video sites go, generally I don't have uMatrix set up to allow them to work in the first place so I just turn to my alternate browser. I only have YouTube set up in my main Firefox because I wind up on it so often and it's relatively easy.)

Written on 27 April 2018.
« The shifting goals of our custom NFS mount authorization system
What sorts of good email attachments our users get (April 2018 edition) »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Apr 27 01:13:10 2018
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.