I\'m trying to use the onMessage listener. The website is executing a postMessage (window.postMessage(\"Post message from web\");) but react native\'s webview o
According to this issue, you need to wait until the React Native postMessage has replaced the native window.postMessage (don’t ask me why they are replacing a native function instead of creating a new one).
One solution is to do something like:
function waitForBridge() {
//the react native postMessage has only 1 parameter
//while the default one has 2, so check the signature
//of the function
if (window.postMessage.length !== 1){
setTimeout(waitForBridge, 200);
}
else {
window.postMessage('abc');
}
}
window.onload = waitForBridge;