Skip to content

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

@jim-daf

Description

@jim-daf

WebPageView (app/src/main/java/com/codelv/inventory/MainActivity.kt) is the in-app browser the importers use to load supplier and datasheet pages. The WebViewClient overrides shouldInterceptRequest, doUpdateVisitedHistory, onPageStarted and onPageFinished, but not shouldOverrideUrlLoading. Every navigation, including non http(s) schemes the supplier page hands the WebView, runs through the default WebView handler.

In practice that means:

  1. A mailto: link on a Mouser / Digikey contact row tries to load mailto: as a web URL and shows a blank page.
  2. A tel: link does the same.
  3. An intent: URL from a deep link can hit the default WebView handler instead of being routed to the app the URL targets.

The existing TODO in this file (// WARNING: This only appears to work for GET requests and does not block a majority of the garbage requests) is on shouldInterceptRequest, which fires for sub-resources. URL routing on top-level navigations is a separate hook (shouldOverrideUrlLoading).

Suggested fix

Add a shouldOverrideUrlLoading override before the existing ones. Keep http, https and about: schemes inside the WebView, route the rest out via Intent.ACTION_VIEW, and wrap the launch in try/catch so a missing handler does not crash the Compose 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
    }
}

A PR with the change is at #13.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions