2

I wonder how i can catch and handle WebKit Errors in my iPad App. I found no information about ErrorDomain and ErrorCodes up till now. Is this a miracle?

This is what i see from time to time at the console in Xcode during testing on device (iPad2, iOS 5.0.1).

WebKit discarded an uncaught exception in the webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: delegate: <(null)> A route has already been registered for class 'Publication' and HTTP method 'ANY'

How can i catch WebKit Errors? This Error raises during an alert(); in JS within the HTML Page that's loaded in a UIWebView.

MadMaxAPP
  • 1,035
  • 2
  • 16
  • 39

2 Answers2

1

I am not sure but maybe the:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error

could put some light on that issue (that's UIWebViewDelegate). Set the delegate and implement this method. Print the error description to the console and check it.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • I have this implemented, but it seems this doesn't be called in this situation. – MadMaxAPP Nov 25 '11 at 22:47
  • I came accross this [link](http://stackoverflow.com/questions/193119/how-can-my-iphone-objective-c-code-get-notified-of-javascript-errors-in-a-uiwebv), describing how to catch java script errors. Maybe this will help. – Rafał Sroka Nov 26 '11 at 09:39
  • There seems to be a large Impact in Performance, and I don't know what HTML Content will be loaded in future within the UIWebView. Is there no way to catch errors in WebKit? If WebKit can crash the whole App because of something within HTML / JS then it should be possible to catch that?! – MadMaxAPP Nov 28 '11 at 15:13
0

Here is a Swift 3 version of RaffAl's answer.

func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
     print("An error occurred!: \(error)")
}