解决 Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined.
2017-09-22 20:33
585 查看
![](https://images2017.cnblogs.com/blog/596869/201709/596869-20170922202824290-1854104169.png)
在 issue 里并没有找到官方的解决办法:不过下面这段代码,就可以不在崩溃!
let getTitle: Function = function(url: string) { setTimeout(function() { // 防止postMessage崩溃 var originalPostMessage = window.postMessage; var patchedPostMessage = function( message: any, targetOrigin: string, transfer?: any[] ) { originalPostMessage(message, targetOrigin, transfer); }; patchedPostMessage.toString = function() { return String(Object.hasOwnProperty).replace( "hasOwnProperty", "postMessage" ); }; window.postMessage = patchedPostMessage; window.postMessage(JSON.stringify({ title: document.title }), url); }, 0); }; let titleJs = "(" + String(getTitle) + ")();";
https://github.com/facebook/react-native/issues/10865#issuecomment-269847703
相关文章推荐
- Android异常解决--A WebView method was called on thread 'JavaBridge'. All WebView methods must be called
- 报错'An instance 0x7fb441883000 of class UITableView was deallocated while key value observers we 解决方法
- -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
- 关于Android WebView不支持window.location.href的解决方法
- Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 解决办法
- hibernate Null value was assigned to a property of primitive type setter of 错误解决
- 当Xib文件删掉之后,解决报错信息:NSInternalInconsistencyException loaded xxx nib but the view outlet was not set.
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable解决方法
- 怎么解决 showModalDialog is deprecated. Please use window.open and postMessage instead.
- 解决BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type XXX, but was actually of type XXX问题
- An instance 0x15718ca00 of class UITableView was deallocated while key value observers were still re
- WebView控件中的onConsoleMessage方法不被调用
- emulator window was out of view and was recentered
- 关于eclipse新建web项目,提示:"The superclass "javax.servlet.http.HttpServlet" was not found on the Java"解决办法
- 服务器的日志一直报Packet for query is too large (7632997 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.的解决方法
- iOS - 解决the behavior of the UICollectionViewFlowLayout is not defined
- IOS loaded the "XXXXXView" nib but the view outlet was not set.' 解决办法
- Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.... 此错误的解决方法
- [转]Null value was assigned to a property of primitive type setter of"原因及解决方法
- 浅谈WebView在新窗口浏览网页(setSupportMultipleWindows()与onCreateWindow()关系)