Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMP WebView to Web Communication #227

Open
khalid64927 opened this issue Sep 22, 2024 · 2 comments
Open

CMP WebView to Web Communication #227

khalid64927 opened this issue Sep 22, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@khalid64927
Copy link

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
Copy link

JNY0606 commented Sep 23, 2024

[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]

<script> function gogo(msg, cb) { alert(msg) cb('from js') } </script>

[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
Copy link
Owner

@khalid64927 Please refer to this link

@KevinnZou KevinnZou self-assigned this Sep 23, 2024
@KevinnZou KevinnZou added the enhancement New feature or request label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants