美文网首页
React native WebView 遇到的问题

React native WebView 遇到的问题

作者: 海利昂 | 来源:发表于2019-02-26 11:02 被阅读0次

解决办法 

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} />

相关文章

网友评论

      本文标题:React native WebView 遇到的问题

      本文链接:https://www.haomeiwen.com/subject/iezoyqtx.html