I have a WebView in an android app. Sometimes, the page in the webview does not show. This happens randomly: for the same page, it sometimes appears, sometimes does not. Despite the page not showing, a blank area occupies the appropriate amount of space (I know because below the webview there are other controls). The curious thing is that if I inspect the webview with chrome://inspect, the page is there and shows up correctly.
When the problem happens, if I perform small changes in the html through the DevTools, the same effect persists: the new page appears in the DevTools view but, in the device, a blank space is shown with the area that should be occupied by the new page. The page only shows when I change something in the html/css that makes it resize a lot.
The app uses Jetpack Compose and uses WebView by means of AndroidView. When the problem happens, the following backtrace appears sometimes in logcat:
2021-02-16 16:08:34.866 9683-9698/... E/System: Uncaught exception thrown by finalizer
2021-02-16 16:08:34.909 9683-9698/... E/System: java.lang.IllegalStateException: Warning: Router objects should be explicitly closed when no longer required otherwise you may leak handles.
at w4.finalize(chromium-TrichromeWebViewGoogle.aab-stable-432415233:4)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:289)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:276)
at java.lang.Daemons$Daemon.run(Daemons.java:137)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.Exception: AutocloseableRouter allocated at:
at w4.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:4)
at vu.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:8)
at org.chromium.content.browser.framehost.RenderFrameHostImpl.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:10)
at org.chromium.content.browser.framehost.RenderFrameHostImpl.create(chromium-TrichromeWebViewGoogle.aab-stable-432415233:1)
at J.N.MZAK3_Tx(Native Method)
at org.chromium.content.browser.webcontents.WebContentsImpl.E0(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at qP.renderFrameDeleted(chromium-TrichromeWebViewGoogle.aab-stable-432415233:2)
at org.chromium.content.browser.webcontents.WebContentsObserverProxy.renderFrameDeleted(chromium-TrichromeWebViewGoogle.aab-stable-432415233:2)
at J.N.MQGusfGb(Native Method)
at v5.run(chromium-TrichromeWebViewGoogle.aab-stable-432415233:2)
at ze.handleMessage(chromium-TrichromeWebViewGoogle.aab-stable-432415233:21)
at Be.a(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at Be.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at org.chromium.android_webview.AwContents.M(chromium-TrichromeWebViewGoogle.aab-stable-432415233:88)
at org.chromium.android_webview.AwContents.L(chromium-TrichromeWebViewGoogle.aab-stable-432415233:2)
at org.chromium.android_webview.AwContents.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:67)
at L60.run(chromium-TrichromeWebViewGoogle.aab-stable-432415233:9)
at L80.b(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at J80.run(chromium-TrichromeWebViewGoogle.aab-stable-432415233:1)
at org.chromium.base.task.PostTask.c(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at L80.a(chromium-TrichromeWebViewGoogle.aab-stable-432415233:3)
at com.android.webview.chromium.WebViewChromium.init(chromium-TrichromeWebViewGoogle.aab-stable-432415233:77)
at android.webkit.WebView.<init>(WebView.java:429)
at android.webkit.WebView.<init>(WebView.java:353)
at android.webkit.WebView.<init>(WebView.java:336)
at android.webkit.WebView.<init>(WebView.java:323)
at android.webkit.WebView.<init>(WebView.java:313)
(my invocation)
I am using WebView as follows:
@Composable
fun WebViewView(
html: String,
baseUrl: String? = null
) {
AndroidView({ context ->
val webView = WebView(context)
// configure webview
webview
})
}
What can be the cause of this?