Skip to content

Commit 30f3f0a

Browse files
committed
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.
1 parent 95d48cd commit 30f3f0a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java

100755100644
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ public class DefaultWebClient extends MiddlewareWebClientBase {
146146
* SMS scheme
147147
*/
148148
public static final String SCHEME_SMS = "sms:";
149+
/**
150+
* file scheme - locally bundled assets and on-device files.
151+
*/
152+
public static final String FILE_SCHEME = "file://";
153+
/**
154+
* javascript: scheme - bookmarklet-style URLs the WebView itself evaluates.
155+
*/
156+
public static final String JAVASCRIPT_SCHEME = "javascript:";
149157
/**
150158
* 缓存当前出现错误的页面
151159
*/
@@ -189,6 +197,13 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
189197
if (url.startsWith(HTTP_SCHEME) || url.startsWith(HTTPS_SCHEME)) {
190198
return (webClientHelper && HAS_ALIPAY_LIB && isAlipay(view, url));
191199
}
200+
// Issue #762: navigations to file:// (e.g. links between bundled assets)
201+
// and javascript: URLs must be handled by WebView itself. Letting them
202+
// fall through into the unknown-URL branch below causes
203+
// mIsInterceptUnkownUrl to silently drop the navigation.
204+
if (url.startsWith(FILE_SCHEME) || url.startsWith(JAVASCRIPT_SCHEME)) {
205+
return false;
206+
}
192207
if (!webClientHelper) {
193208
return super.shouldOverrideUrlLoading(view, request);
194209
}
@@ -278,6 +293,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
278293
if (url.startsWith(HTTP_SCHEME) || url.startsWith(HTTPS_SCHEME)) {
279294
return (webClientHelper && HAS_ALIPAY_LIB && isAlipay(view, url));
280295
}
296+
// Issue #762: navigations to file:// (e.g. links between bundled assets)
297+
// and javascript: URLs must be handled by WebView itself. Letting them
298+
// fall through into the unknown-URL branch below causes
299+
// mIsInterceptUnkownUrl to silently drop the navigation.
300+
if (url.startsWith(FILE_SCHEME) || url.startsWith(JAVASCRIPT_SCHEME)) {
301+
return false;
302+
}
281303
if (!webClientHelper) {
282304
return false;
283305
}

0 commit comments

Comments
 (0)