-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Android window.ReactNativeWebView.postMessage issue #323
Comments
Can you dig more? Same scenario is working fine on my own app :) |
Been digging a lot. We've found that a downgrade to 4.1.0 works. Are there known issues with certain Android versions maybe? |
Not that I'm aware of 🤔 . Did you rebuild the native side of the app after upgrade? |
It's |
@tapir see #324 (comment) |
The reference is correct, it also works on iOS but not in Android. We rebuilt de app multiple times from scratch removing all intermediate files, still no succes. The downgrade does work to 4.1.0 but that's kind a odd as you say that the latest should work as well. |
@RobinUS2 I'm using latest in production, so it is working. There must be something we are missing here. |
@Titozzz I agree, it must be something very subtle. Could you share a skeleton project or something where you implement this so we can review line by line, character (and case 😉 ) to see what's going on? |
same here, android lollipop 5.0.2 |
@RobinUS2 Can you instead submit a small reproduction of the bug? |
Sorry, my faults, upgraded from 2.x. missed the breaking change note in 5.0 |
My RN webview needs to communicate to a remote page of my website that uses ReactJS. On the webpage, I see that the
as indicated in the release notes to get it working.Is it a bug? I find it odd that the |
because overriding an existing postMessage function was a bad practice, and instead we decided to scope it inside an object. Since you have control over your react app directly I would advise against doing that and calling |
@Titozzz |
please test more because the method does exist 😄 |
@Titozzz If the
|
Yeah, this is the second reason we moved it actually because using '*' was a security issue 👍 |
#363 /*ios*/
/*>*/window/*<*/.addEventListener('message', this.messageReceived);
/*droid*/
/*>*/document/*<*/.addEventListener('message', this.messageReceived); however it looks like disparity is not intentional and will be ironed out. to push it furtherer since we have a separate bridge to communicate to sent messages RN why not re-use it to send events down to WebView too... smth like ReactNativeWebView.onMessage(this.messageReceived) maybe it would also make sense to use a different name for postMessage to avoid confusion related to browser's postMessage signature? ReactNativeWebView.sendMessage(m) @RobinUS2, @Titozzz, @jamonholmgren, what do you guys think? any opinion/thoughts on this? |
Thanks! It works really well. |
@victor-ca webview.postMessage is not documented and I would advise against using it, I personally use injectJavascript, it allows better flexibility. See here for a demo of what you could do #66 (comment) |
I just had the same error and narrowed it down in my case to a javascript binding issue. You can easily reproduce the
By assigning to a local variable and calling that, javascript is changing the functions
As a real world example and the reason I came across this was for some code which was shared between hosting in a WebView or an iframe and I was trying to do this:
|
"react-native": "0.58.6" still reproduce on Android 7 and lower |
@guavadevelopment You saved my ass! |
Thanks bro |
Hi there,
We implemented version 5.0.5 of the library with #243 incorporated into it using
window.ReactNativeWebView.postMessage
for bidirectional communication. We use both iOS and Android with "react-native": "0.57.0".The problem we see is the following:
iOS => web view => ✅ (use
injectJavaScript
to send a message)web view => iOS => ✅ (use
window.ReactNativeWebView.postMessage
to send a message)Android => web view => ✅ (use
injectJavaScript
to send a message)web view => Android => 👎 (use
window.ReactNativeWebView.postMessage
to send a message)Android errors with:
This feels somewhat weird, since the whole java bridge is supposed to be managed for us, as long as messagingEnabled=true, which is computed from
messagingEnabled={typeof this.props.onMessage === 'function'}
. Our WebView hasonMessage
implemented with a function, so that all should be good, and is also "confirmed" by the fact that iOS works as expected.Am I missing something obvious, or is this a bug?
Thanks in advance!
The text was updated successfully, but these errors were encountered: