Skip to content

In-app browser WebView swallows page-load errors with no indication to the user #60

@jim-daf

Description

@jim-daf

WebViewFragment.kt:48 is the in-app browser the user types or navigates a URL into so it can be picked for monitoring. The WebViewClient overrides onPageStarted to show the progress bar and onPageFinished to hide it, but there is no onReceivedError override:

webview.webViewClient = object : WebViewClient() {

    override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
        refreshBack(view)
        updateUrl(url)
        progress?.visibility = View.VISIBLE
        super.onPageStarted(view, url, favicon)
    }

    override fun onPageFinished(view: WebView?, url: String?) {
        refreshBack(view)
        updateUrl(url)
        progress?.visibility = View.GONE
        super.onPageFinished(view, url)
    }
}

When the user types something that fails to load (DNS error, certificate problem, offline, 4xx/5xx, etc.), onPageFinished still fires eventually but the WebView is left displaying a blank area with no indication of why the page did not show up. From the user's side it just looks like the app stopped working.

Suggested fix

Add an onReceivedError override that hides the progress bar and surfaces a short Toast with the failure reason. Gate it on request.isForMainFrame == true so every blocked sub-resource on a page does not also pop a Toast. Add a couple of strings (webview_load_failed, webview_load_failed_with_reason) so the message stays translatable.

A PR with that change is open at #61.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions