oiledCode
oiledCode

Reputation: 8649

UIWebView - Debug javascript

I'm facing the following problem : my app has to load some web-content and for some reason the content isn't rendered as it should be,(the web content works perfectly on mobile safari). So I need a way to get notified of javascript error in a UIWebView.

I read thisanswer but I'm actually not able to make it works :(

Could someone,that already did this, please explain me how to do?

Another question is : the UIWebView in iOS 5.x integrate the nitro engine? becaue someone say yes others say no....

Thanks in advance

Upvotes: 4

Views: 4729

Answers (1)

jamesh
jamesh

Reputation: 20091

I have been running quite a lot of Javascript an invisible webview.

Debugging Javascript on iOS is somewhat tricky. The following I have found helpful, although I have found no silver bullets:

  • There is no console.log. I implemented it myself, using the same - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType everyone else uses.
  • There are facilities for remote debugging in iOS 5.x. You can set break points, inspect variables etc, but no step-by-step debugger. iOS imposes a hard limit of 10s where if a javascript call is taking its time, then it will be terminated without warning. This makes this debug bridge considerably less useful.
  • iOS 5.x has terrible Errors. No stack traces, no line numbers, no filenames, nothing. Quite frequently I'm stuck with a 'undefined' is not a function with no extra help.
  • iOS 4.3 has better errors. Still no stack traces, but line numbers and filenames exist.
  • There is a method - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error; which as a long shot may report Javascript errors. It doesn't.

Things I haven't tried, but are on my list:

  • Weinre looks interesting, if a little heavy for my purposes.
  • JSConsole looks like a winner, though may not be very helpful for debugging errors.

Upvotes: 3

Related Questions