I need to catch errors that occur in WebView if WebView is present in the screen. That is not to bind to a specific WebView.
3 Answers
Not sure if you have already tried this solution,You can catch the exception in your JS code and call a native method to log this information. You can inject this native method implementation into JS context of the UIWebview after a receiving below UIWebView delegate callback that JS context for the webView has been created.
- (void)webView:(id)webView didCreateJavaScriptContext:(JSContext *)context forFrame:(id)frame {
//this injects the MyNativeLog in your UIWebView JS context and you can call this function in your JS code.
context[@"MyNativeLog"] = ^(NSString *string){
NSLog(@"%@", string);
};
}
Hope this helps!!
2 Comments
The following may helps you please check the below link which is already exist
How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?
You can hook UIWebView control to hidden WebKit framework and get all exceptions, executed functions and similar.
Comments
You need to use webView:didClearWindowObject:forFrame: method of WebFrameLoadDelegate Protocol.
There you can catch any type of javascript exception that happens to occur. This is not bind to a specific WebView.
UIWebView?WKWebView?not to bind to a specific WebView??