4

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

Community
  • 1
  • 1
oiledCode
  • 8,589
  • 6
  • 43
  • 59
  • Answer which you mentioned isn't about UIWebView but Mac OS's WebView. There are some JS / JQuery functions which are not working well on UIWebView (but Mobile Safari isn't moaning) - for our examples queries in DOM made by JQuery. There's no possibility to track JS errors in UIWebView - you need to get JS files and find out whats going on. – Piotr Nov 24 '11 at 12:44
  • Actually if you read with more attentions the link I've linked, the prcela answer in particular, he said that the workaround works even on iOS. There's also another way to debug in a webview, enabling webkit remote debugging. so the possibility are more than one... – oiledCode Nov 25 '11 at 05:07

1 Answers1

3

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.
jamesh
  • 19,863
  • 14
  • 56
  • 96