From ef400fa47a374c2448231087bd4888c876d4b472 Mon Sep 17 00:00:00 2001 From: Dimitris Dafnis <68849116+jim-daf@users.noreply.github.com> Date: Tue, 21 Apr 2026 21:59:32 +0200 Subject: [PATCH] fix(AbsAgentWebSettings): allow media playback without user gesture (#339) Resolves #339 Issue #339 reports that an embedded video on a page loaded in AgentWeb fails with: Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. The platform default for setMediaPlaybackRequiresUserGesture is true, and AbsAgentWebSettings.settings() never overrides it. Many embedded video players (TikTok/Douyin share pages, Twitter video, etc.) start playback programmatically and break under that default. This change calls mWebSettings.setMediaPlaybackRequiresUserGesture(false) in settings() so the platform's WebView allows programmatic playback, matching the behavior most in-app browsers want. The mixed-content half of the same issue (HTTP video on HTTPS page) is already handled by the existing setMixedContentMode(MIXED_CONTENT_ALWAYS_ALLOW) call further down in the same method. --- .../src/main/java/com/just/agentweb/AbsAgentWebSettings.java | 4 ++++ 1 file changed, 4 insertions(+) mode change 100755 => 100644 agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java diff --git a/agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java b/agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java old mode 100755 new mode 100644 index b723fbc6..2c2c7e1d --- a/agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java +++ b/agentweb-core/src/main/java/com/just/agentweb/AbsAgentWebSettings.java @@ -65,6 +65,10 @@ private void settings(WebView webView) { mWebSettings.setSupportZoom(true); mWebSettings.setBuiltInZoomControls(false); mWebSettings.setSavePassword(false); + // Issue #339: HTMLMediaElement.play() throws "API can only be initiated by + // a user gesture" for embedded video players that auto-play. Allow + // programmatic playback so embedded players (e.g. share-page videos) work. + mWebSettings.setMediaPlaybackRequiresUserGesture(false); if (AgentWebUtils.checkNetwork(webView.getContext().getApplicationContext())) { //根据cache-control获取数据。 mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT);