Three.js doesn't work in Android's WebView

I’m trying to load Three.js in Android 14 (API 34) but the canvas of every demo I tried so far is black and there is no error in the logs (the webpage itself loads).

Does anyone know of any solution?

@Composable
fun WebViewExample() {
    val url = "https://threejs.org/examples/webgl_camera.html"

    Column(
        modifier = Modifier.fillMaxSize()
    ) {
        AndroidView(
            factory = { context ->
                WebView(context).apply {
                    webViewClient = WebViewClient()
                }
            },
            update = { webView ->
                if (webView.url != url) {
                    webView.loadUrl(url)
                }
            },
            modifier = Modifier.fillMaxSize()
        )
    }
}

I solved it by adding settings.javaScriptEnabled = true.

It shows a warning though: Using setJavaScriptEnabled can introduce XSS vulnerabilities into your application, review carefully

1 Like