UIWebView - javascript debugging

I ran into the following problem: my application needs to download some web content, and for some reason the content is not displayed as it should (web content works fine on mobile safari). So I need to get javascript error notification in UIWebView.

I am reading this answer, but actually I cannot get it to work :(

Can someone who has already done this explain me how to do this?

Another question: Does UIWebView integrate nitro engine in iOS 5.x? because someone says yes, others say no ....

Thank you in advance

+4
source share
1 answer

I have run quite a lot of Javascript of an invisible web view.

Debugging Javascript on iOS is somewhat complicated. The following, which I found useful, although I did not find silver bullets:

  • No console.log . I myself implemented it using the same - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType , which uses all the others.
  • There are tools for remote debugging in iOS 5.x. You can set breakpoints, check variables, etc., but not a step-by-step debugger. iOS imposes a hard limit of 10 s, if during javascript call its time is interrupted, it will be terminated without warning. This makes this debug bridge much less useful.
  • iOS 5.x has terrible bugs. No stack traces, no line numbers, no file names, nothing. Quite often, I get stuck with 'undefined' is not a function without any extra help.
  • iOS 4.3 has the best bugs. There is still no stack trace, but line numbers and file names exist.
  • There is a method - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error; , which, like a long shot, can report Javascript errors. This is not true.

Things I have not tried but are on my list:

  • Weinre looks interesting if a little hard for my purposes.
  • JSConsole looks like a winner, but may not help much when debugging errors.
+3
source

Source: https://habr.com/ru/post/1382524/


All Articles