postMessage or onMessage not working android?
See original GitHub issueI need to send a message to react native through the website. It works as expected in ios when I do it as below. But it doesn’t work on android
website code (x.com)
let sendMessageToNative = () =>{
let url = window.location.href
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(url, '*')
}
sendMessageToNative()
react native code
<WebView
allowsBackForwardNavigationGestures={true}
originWhitelist={['*']}
source={{ uri: 'x.com' }}
startInLoadingState={true}
javaScriptEnabledAndroid={true}
javaScriptEnabled={true}
onMessage={event => {
console.log("eee", event.nativeEvent.data)
alert('MESSAGE >>>>' + event.nativeEvent.data)
}}
ref={webviewRef}
/>
Expected behavior: The url I sent on ios appears on the screen as an alert. This does not happen on Android. The same I sent in the string.the same must be on android
Environment:
- OS: Android
- OS version: Android Version 11 emilator or xiaomi mi 8 lite android version 10
- react-native version: 38
- react-native-webview version: 9.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (1 by maintainers)
Top Results From Across the Web
React Native WebView postMessage does not work
Does anyone know why the web app is not receiving the messages? Tested with both Android and iOS. Related documentation: https://facebook.github ...
Read more >MessageEvent - Web APIs - MDN Web Docs - Mozilla
The MessageEvent interface represents a message received by a target object. This is used to represent messages in:.
Read more >Fixing React Native WebView's postMessage for iOS
Our original problem is already solved — onMessage works with this WebView. However, since we have overwritten the internal onNavigationStateChange listener, ...
Read more >postMessage/onMessage no longer working | Velo by Wix
I am facing similar issue and did not understand the solution completely. Is it possible for you to share the sample code on...
Read more >chrome.runtime - Chrome Developers
onMessage. event. This event is fired when postMessage is called by the other end of the port. The onMessage.addListener function looks like: (callback: ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After trying all the above, I still have this problem: it does not work normally on ios but not on android
still searching for solutions