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

Passing numbers to window.ReactNativeWebview.postMessage does not trigger onMessage callback anymore #3722

Open
eloiqs opened this issue Mar 5, 2025 · 0 comments

Comments

@eloiqs
Copy link

eloiqs commented Mar 5, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant