From 30f3f0aa8fb193be3d28bcd19018cc5501737d4d Mon Sep 17 00:00:00 2001 From: Dimitris Dafnis <68849116+jim-daf@users.noreply.github.com> Date: Tue, 21 Apr 2026 21:57:59 +0200 Subject: [PATCH] fix(DefaultWebClient): allow file:// and javascript: navigations to fall through (#762) Resolves #762 DefaultWebClient.shouldOverrideUrlLoading explicitly handles http/https, then runs through phone/email/intent/wechat/alipay handlers, and finally intercepts every remaining URL when mIsInterceptUnkownUrl is true (the default). file:// links between bundled assets (the most common pattern for offline H5 apps that hit this method) end up in that final branch, which returns true and silently drops the navigation. The same is true of javascript: URLs. Two new scheme constants (FILE_SCHEME / JAVASCRIPT_SCHEME) are added near SCHEME_SMS, and both overloads of shouldOverrideUrlLoading return false as soon as they see one of those schemes, letting WebView handle the navigation itself. --- .../com/just/agentweb/DefaultWebClient.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) mode change 100755 => 100644 agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java diff --git a/agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java b/agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java old mode 100755 new mode 100644 index fcbaa979..28ad530e --- a/agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java +++ b/agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java @@ -146,6 +146,14 @@ public class DefaultWebClient extends MiddlewareWebClientBase { * SMS scheme */ public static final String SCHEME_SMS = "sms:"; + /** + * file scheme - locally bundled assets and on-device files. + */ + public static final String FILE_SCHEME = "file://"; + /** + * javascript: scheme - bookmarklet-style URLs the WebView itself evaluates. + */ + public static final String JAVASCRIPT_SCHEME = "javascript:"; /** * 缓存当前出现错误的页面 */ @@ -189,6 +197,13 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request if (url.startsWith(HTTP_SCHEME) || url.startsWith(HTTPS_SCHEME)) { return (webClientHelper && HAS_ALIPAY_LIB && isAlipay(view, url)); } + // Issue #762: navigations to file:// (e.g. links between bundled assets) + // and javascript: URLs must be handled by WebView itself. Letting them + // fall through into the unknown-URL branch below causes + // mIsInterceptUnkownUrl to silently drop the navigation. + if (url.startsWith(FILE_SCHEME) || url.startsWith(JAVASCRIPT_SCHEME)) { + return false; + } if (!webClientHelper) { return super.shouldOverrideUrlLoading(view, request); } @@ -278,6 +293,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith(HTTP_SCHEME) || url.startsWith(HTTPS_SCHEME)) { return (webClientHelper && HAS_ALIPAY_LIB && isAlipay(view, url)); } + // Issue #762: navigations to file:// (e.g. links between bundled assets) + // and javascript: URLs must be handled by WebView itself. Letting them + // fall through into the unknown-URL branch below causes + // mIsInterceptUnkownUrl to silently drop the navigation. + if (url.startsWith(FILE_SCHEME) || url.startsWith(JAVASCRIPT_SCHEME)) { + return false; + } if (!webClientHelper) { return false; }