What are some methods to debug Javascript inside of a UIWebView?

bpapa picture bpapa · May 4, 2010 · Viewed 93.1k times · Source

I'm trying to figure out why something with Javascript isn't working inside of a UIWebView. To my knowledge, there is no way to set a breakpoint inside of XCode for a js file. No problemo, I'll just go back to 2004 and use alert statemen-- oh wait they don't seem to work inside of a UIWebView either!

The only thing I could think of is by exporting my HTML And JS files to my desktop and then just doing my debugging inside of Safari. And that works! But of course, the bug I'm fighting with in the UIWebView doesn't occur in Safari.

Are there any other ways for debugging inside of a UIWebView, or any tricks that I can use akin to using the old-school alert method?

Answer

refaelos picture refaelos · Sep 23, 2012

If you're using iOS >= 6 and you have mountain lion (10.8) or Safari >= 6, you can just:

  1. Open the application in the simulator (or your device in XCode >= 4.5.x).
  2. Open Safari (go to Preferences -> Advanced and make sure "Show Develop Menu in Menubar" is on.
  3. From the Menu-bar (of Safari) select Develop -> iPhone Simulator -> [your webview page].

That's it !