window.ReactNativeWebView.postMessage is not a function
See original GitHub issueBug description:
I’m getting a strange (and relatively rare) exception reported in Sentry.
window.ReactNativeWebView.postMessage is not a function
This exists within a piece of code that explicitly checks if window.ReactNativeWebView
is present
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage(message)
}
To Reproduce:
Because it happens rarely, I can’t give exact reproduction steps.
However:
- two instances were on a Pixel 4 (technically one of these was a Pixel 4a)
- one instance was on an SM-G996U
This appears to be sporadic, even for any given user. I.e. they will experience the bug briefly then it won’t happen again.
Environment:
- OS: Android
- OS version: “Other” (that’s all Sentry gave us)
- react-native version: 0.68.2
- react-native-webview version: v11.22.1
Remarks
- Is it possible that
window.ReactNativeWebView
needs time to load its properties? - Is it possible that
window.ReactNativeWebView
behaves differently depending on the OS/environment the code finds itself executed in? It seems likepostMessage
is a value instead of a function here.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
React Native WebView postMessage does not work
Show activity on this post. I can't get React Native WebView postMessage to work. The React Native app successfully receives the post message...
Read more >Fixing React Native WebView's postMessage for iOS
We define our own window.postMessage function. The first thing it does is executes the previous window.postMessage function, if it existed.
Read more >WebView - React Native
A function that is invoked when the webview calls window.postMessage . Setting this property will inject a postMessage global into your webview, ...
Read more >Javascript – React Native WebView postMessage does not work
I can't get React Native WebView postMessage to work. The React Native app successfully receives the post message sendt from the web app....
Read more >How to communicate with data between WebViews in React ...
Import the React Native WebView package in App.js . ... to call a sendDataToReactNativeApp() function in which we will use a window property...
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
We have the same the issue, reported by Bugsnag for Android devices.
@17Amir17 Based on the limited information thus far, this sounds like an issue with Android’s WebView that this library can’t do anything about. I could be wrong, but we don’t have a repro and the info from @jackkinsella indicates that we are successfully invoking
addJavascriptInterface
.I would be somewhat curious if
v11.21.2
behave[s|d] any differently, since there was some refactoring inv11.22.0
… I would be surprised if that actually makes a difference though, as I don’t think the refactoring would be related, but there were one or two things that unexpectedly broke there.