Skip to content

Conversation

octocorvus
Copy link

@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 octocorvus marked this pull request as draft October 8, 2022 08:53
@octocorvus octocorvus marked this pull request as ready for review October 13, 2022 14:06
@thestinger thestinger force-pushed the 13 branch 2 times, most recently from 7d82a65 to 451a394 Compare October 14, 2022 03:53
@octocorvus
Copy link
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