Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial support for blocking media autoplay #235

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

octocorvus
Copy link
Member

@octocorvus octocorvus commented Oct 7, 2022

This adds a setting to chrome://flags to block media autoplay. Issue #92

Tested on a real device running Android 13 (GrapheneOS). Working as exepected (details below) on most websites. But in my testing I found that when navigating on the same website (same-origin), autoplay is not always blocked (yet to figure out how to block that). Also, I'm not sure if this is the only case where autoplay is not blocked; it needs more testing.

I'll make a UI for this later (once this feature is ready).

How it works:
See autoplay flowchart. If the feature/flag kBlockMediaAutoplay is enabled, AutoplayPolicy will block any attempts to:

  • autoplay by setting the autoplay attribute on the media element
  • autoplay by explicitly calling play() on the media element
  • unmute media, setMuted(false) (I'm not sure if this needs to be done, since autoplay is already blocked)

@octocorvus
Copy link
Member Author

Update on autoplay policy:

I split the functionality into three patches:

  1. Implement experimental Autoplay site setting, it is currently behind the flag #enable-autoplay-permission (it is mostly boilerplate code and likely won't change much over time).
  2. Add AllowAutoplay in WebContentSettingsClient. It allows accessing the Autoplay setting in the renderer, blink (also, mostly boilerplate code and likely won't change much over time).
  3. Implement the below autoplay policy.

Current autoplay policy (if autoplay is blocked for site as per content settings):

  1. Muted autoplay is always blocked.
  2. Autoplay with sound is allowed if and only if the user has interacted with domain (click, tap, etc.). If we block this, then the user won't be able to start a video by tapping on the play button, since those will be blocked too.

@thestinger
Copy link
Member

@octocorvus needs to be rebased again

... when not allowed by content settings.

This commit adds four patches:

1. Add enable-autoplay-permssion flag to the renderer.
2. Implement experimental Autoplay site setting (behind a flag).
3. Add AllowAutoplay in WebContentSettingsClient (allows accessing the
   Autoplay setting in the renderer (blink).
4. Implement the below autoplay policy.

Current autoplay policy (if autoplay is blocked for site as per content
settings):
1. Muted autoplay is always blocked.
2. Autoplay with sound is allowed if and only if the user has interacted
   with domain (click, tap, etc.). If we block this, then the user won't
   be able to start a video by tapping on the play button, since those
   will be blocked too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants