Passing numbers to window.ReactNativeWebview.postMessage does not trigger onMessage callback anymore
Bug description:
postMessage(0) used to properly trigger onMessage callback with data being coerced to string somehow, and it is not the case anymore
Im aware docs specify passing string only, but we dont own the code calling us unfortunately... Our current workaround is to inject js that instruments postMessage to force a String coerscion like
if (window.ReactNativeWebView) {
const postMessage = window.ReactNativeWebView.postMessage.bind(window.ReactNativeWebView);
window.ReactNativeWebView.postMessage = function _postMessage(data) {
postMessage(String(data));
}
}
To Reproduce: I have set it up for you here 🙂 https://github.com/eloiqs/react-native-webview-regression-repro
Expected behavior: Not sure if we want to fix this here and bring back the coerscion because I agree with the docs specify string only, but it used to work. At the very least this issue can be useful to others seeking workarounds.
Screenshots/Videos: There are videos in my repo 🙂
Environment: Im not certain this isnt happening on some ios devices, or not happening on some android device, but we could consistently reproduce with those
- OS: android
- OS version: android 15 / sdk 35
- react-native version: .77
- react-native-webview version: 13.13.2
My repo shows it works on react-native .76 and webview 13.12.5
Im having the same provlem. it started when i updated to the 13.13.2
when i rollback to the version 13.10.5 it works well.
same issue
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically
Thank you for pointing this out, helped fixing the issue on our side.
Could be because of how WebMessageCompat works under the hood (implemented in v13.13.1)? https://github.com/react-native-webview/react-native-webview/pull/3609/files#diff-e15c72676fc096ed252a276e1a7224367e53c89e804fe8351f4d0c6cc2819b59R259