RN Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined错误
发布日期:2022-04-05 00:52:16 浏览次数:3 分类:博客文章

本文共 899 字,大约阅读时间需要 2 分钟。

在使用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属性

 

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

转载地址:https://www.cnblogs.com/lijianyi/p/13530190.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UITableViewCell 内部刷新
下一篇:RN TextInput使用小记

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月01日 09时11分06秒