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:
- A
mailto: link on a Mouser / Digikey contact row tries to load mailto: as a web URL and shows a blank page.
- A
tel: link does the same.
- 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.
WebPageView(app/src/main/java/com/codelv/inventory/MainActivity.kt) is the in-app browser the importers use to load supplier and datasheet pages. TheWebViewClientoverridesshouldInterceptRequest,doUpdateVisitedHistory,onPageStartedandonPageFinished, but notshouldOverrideUrlLoading. Every navigation, including non http(s) schemes the supplier page hands the WebView, runs through the default WebView handler.In practice that means:
mailto:link on a Mouser / Digikey contact row tries to loadmailto:as a web URL and shows a blank page.tel:link does the same.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 onshouldInterceptRequest, which fires for sub-resources. URL routing on top-level navigations is a separate hook (shouldOverrideUrlLoading).Suggested fix
Add a
shouldOverrideUrlLoadingoverride before the existing ones. Keephttp,httpsandabout:schemes inside the WebView, route the rest out viaIntent.ACTION_VIEW, and wrap the launch intry/catchso a missing handler does not crash the Compose activity.A PR with the change is at #13.