zoukankan      html  css  js  c++  java
  • RN Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined错误

    在使用RN的WebView时有时会弹出:

    Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined 错误的一个界面,关闭后不影响正常使用。

    简述下解决方案:

    1、在使用WebView的界面添加如下代码

    patchPostMessageFunction = function() {
            var originalPostMessage = window.postMessage;
          
            var patchedPostMessage = function(message: any, targetOrigin: string, transfer: Transferable[] | undefined) { 
              originalPostMessage(message, targetOrigin, transfer);
            };
          
            patchedPostMessage.toString = function() { 
              return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
            };
          
            window.postMessage = patchedPostMessage;
          };
          
         patchPostMessageJsCode = '(' + String(this.patchPostMessageFunction) + ')();';

    2、WebView中设置injectedJavaScript属性

    <WebView
                        injectedJavaScript={this.patchPostMessageJsCode} 
                    />

    参考地址:https://github.com/facebook/react-native/issues/10865#issuecomment-269847703

  • 相关阅读:
    (全国多校重现赛一) H Numbers
    (全国多校重现赛一)E-FFF at Valentine
    (全国多校重现赛一)B-Ch's gifts
    (全国多校重现赛一)A-Big Binary Tree
    UVA-10391 Compoud Words
    HDU-1027Ignatius and princess II
    CodeForces-501B
    UVA-136Ugly numbers
    UVA-101
    UVA-10474
  • 原文地址:https://www.cnblogs.com/lijianyi/p/13530190.html
Copyright © 2011-2022 走看看