Setting onMessage on a WebView overrides existing values of window.postMessage,
but a previous value was defined.
injectedJavascript should instead be the following
(function() { var originalPostMessage = window.postMessage; var patchedPostMessage = function(message, targetOrigin, transfer) { originalPostMessage(message, targetOrigin, transfer); }; patchedPostMessage.toString = function() { return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage'); }; window.postMessage = patchedPostMessage; })();
And then it works! ?
And if any one is interested, in my code instead of writing a giant string I did the following
const patchPostMessageFunction = function() { var originalPostMessage = window.postMessage; var patchedPostMessage = function(message, targetOrigin, transfer) { originalPostMessage(message, targetOrigin, transfer); }; patchedPostMessage.toString = function() { return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage'); }; window.postMessage = patchedPostMessage; }; const patchPostMessageJsCode = '(' + String(patchPostMessageFunction) + ')();'; ... <WebView injectedJavaScript={patchPostMessageJsCode} />