BrowserClient (app/src/main/kotlin/io/github/landwarderer/futon/browser/BrowserClient.kt:20) tracks the loading state of the in-app browser via the BrowserCallback.onLoadingStateChanged(isLoading: Boolean) callback. It overrides onPageStarted (isLoading = true) and onPageFinished (isLoading = false) but does not override onReceivedError:
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
callback.onLoadingStateChanged(isLoading = true)
}
override fun onPageFinished(webView: WebView, url: String) {
super.onPageFinished(webView, url)
callback.onLoadingStateChanged(isLoading = false)
}
On many failure modes (DNS, certificate, offline, 4xx/5xx) the WebView reports the failure through onReceivedError and onPageFinished does not always fire afterwards. When that happens the toolbar / progress UI driven by onLoadingStateChanged stays stuck on isLoading = true even though the page never loaded.
Suggested fix
Add a main-frame-only onReceivedError override that also flips isLoading = false:
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?,
) {
super.onReceivedError(view, request, error)
if (request?.isForMainFrame == true) {
callback.onLoadingStateChanged(isLoading = false)
}
}
isForMainFrame keeps a single blocked sub-resource from prematurely flipping the spinner off while the main load is still running.
A PR with the addition is open at #68.
BrowserClient(app/src/main/kotlin/io/github/landwarderer/futon/browser/BrowserClient.kt:20) tracks the loading state of the in-app browser via theBrowserCallback.onLoadingStateChanged(isLoading: Boolean)callback. It overridesonPageStarted(isLoading = true) andonPageFinished(isLoading = false) but does not overrideonReceivedError:On many failure modes (DNS, certificate, offline, 4xx/5xx) the WebView reports the failure through
onReceivedErrorandonPageFinisheddoes not always fire afterwards. When that happens the toolbar / progress UI driven byonLoadingStateChangedstays stuck onisLoading = trueeven though the page never loaded.Suggested fix
Add a main-frame-only
onReceivedErroroverride that also flipsisLoading = false:isForMainFramekeeps a single blocked sub-resource from prematurely flipping the spinner off while the main load is still running.A PR with the addition is open at #68.