9

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.

1
  • UIWebView? WKWebView? not to bind to a specific WebView ?? Commented May 26, 2016 at 11:40

3 Answers 3

4
+50

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!!

Sign up to request clarification or add additional context in comments.

2 Comments

Vadim Denisuk, Please accept the answer if it works for you.
Chandra, I do not need to call the code from JavaScript. I will not have access to the javaScript code.
1

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

0

You need to use webView:didClearWindowObject:forFrame: method of WebFrameLoadDelegate Protocol.

Check this: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebFrameLoadDelegate_Protocol/#//apple_ref/occ/instm/NSObject/webView:didClearWindowObject:forFrame:

There you can catch any type of javascript exception that happens to occur. This is not bind to a specific WebView.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.