KevinnZou / compose-webview-multiplatform

WebView for JetBrains Compose Multiplatform
https://kevinnzou.github.io/compose-webview-multiplatform/
Apache License 2.0
514 stars 68 forks source link

CMP WebView to Web Communication #227

Open khalid64927 opened 1 month ago

khalid64927 commented 1 month ago

Hi,

This is possibly a feature request. I have a use case where I need to send some json data to webpage being loaded in WebView Composable and possible handle some events coming from loaded web page. There has to be a two way communication between Mobile Platform WebView and Web Platform.

In iOS/Android Native I can achieve this with JavaScript injection.

I was wondering if there is any API available in this library for that.

JNY0606 commented 1 month ago

[App.kt] val state = rememberWebViewStateWithHTMLFile("index.html") val jsBridge = rememberWebViewJsBridge() val navi = rememberWebViewNavigator()

WebView( state, webViewJsBridge = jsBridge, navigator = navi )

navi.evaluateJavaScript("gogo('from kot')", { msg -> println(msg) })

[index.html]

[Conclusion] Error Message: Uncaught ReferenceError: gogo is not defined Unfortunately, it didn't work for me, so I reverted back to the native webview.

KevinnZou commented 1 month ago

@khalid64927 Please refer to this link