Skip to content

fix(webview): route non http(s) schemes out of WebPageView#13

Open
jim-daf wants to merge 1 commit into
codelv:masterfrom
jim-daf:fix/webview-route-non-http-schemes
Open

fix(webview): route non http(s) schemes out of WebPageView#13
jim-daf wants to merge 1 commit into
codelv:masterfrom
jim-daf:fix/webview-route-non-http-schemes

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented May 16, 2026

Closes #12.

WebPageView's WebViewClient overrides shouldInterceptRequest, doUpdateVisitedHistory, onPageStarted and onPageFinished, but not shouldOverrideUrlLoading. Any navigation the loaded supplier page hands the WebView (a mailto: on a contact link, a tel: on a phone number, an intent: from a deep link) is dispatched by the default handler instead of leaving the in-app browser for the matching system app.

Change

Add a shouldOverrideUrlLoading override. Keep http, https and about: schemes inside the WebView, route the rest out via Intent.ACTION_VIEW, wrap the launch in try/catch (ActivityNotFoundException) so a missing handler does not crash the activity:

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
    val target = request?.url ?: return false
    val scheme = target.scheme?.lowercase()
    if (scheme == "http" || scheme == "https" || scheme == "about") return false
    return try {
        val intent = Intent(Intent.ACTION_VIEW, target).apply {
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }
        view?.context?.startActivity(intent)
        true
    } catch (e: ActivityNotFoundException) {
        Log.w("webview", "No handler for $target", e)
        true
    }
}

This sits alongside the existing WARNING comment on shouldInterceptRequest. The two hooks serve different roles (one for sub-resource requests, one for top-level navigations) so it does not replace the existing intercept logic.

WebPageView's WebViewClient overrides shouldInterceptRequest,
doUpdateVisitedHistory, onPageStarted and onPageFinished but does not
override shouldOverrideUrlLoading. Any navigation the loaded supplier
page hands the WebView (mailto: on a contact link, tel: on a phone
number, intent: from a deep link) is dispatched by the default handler
and stays inside the in-app browser.

Override shouldOverrideUrlLoading to keep http(s) and about: schemes
inside the WebView and route the rest via Intent.ACTION_VIEW, wrapping
the launch in try/catch so a missing handler does not crash the
Activity.
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.

WebPageView swallows non http(s) links (mailto, tel, intent)

1 participant