0

I am using Accompanist library to implement WebView changes in Android Jetpack Compose.

https://google.github.io/accompanist/web/

            WebView(
                state = state,
                modifier = Modifier.weight(1f),
                onCreated = { webView ->
                    webView.settings.javaScriptEnabled = true
                },
                client = webClient
            )

I am not seeing any examples to add addJavascriptInterface to intercept toggle on/off interactions from WebView page.

Is this is possible with AccompanistWebView?

Nico
  • 2,570
  • 1
  • 9
  • 17
Chait
  • 537
  • 6
  • 15

1 Answers1

1

you can use console messages to observer actions, on the webView:

            val currentWebView: WebView? = null
            WebView(
                state = state,
                modifier = Modifier.weight(1f),
                onCreated = { webView ->
                    currentWebView = webView
                    webView.settings.javaScriptEnabled = true
                },
                client = webClient
            )

            currentWebView?.webChromeClient = object : WebChromeClient() {
                override fun onConsoleMessage(consoleMessage: ConsoleMessage):Boolean {
                    // Observer messages here
                    return true
                }
            }