I'm using iOS 6 simulator with the shiny new Web Inspector in Safari.
Question: Is it possible to automatically load the Web Inspector when the iOS 6 web application loads?
I'm using PhoneGap/Cordova and have a lot of javascript loading on startup. I use console.log()
extensively for debugging and would like it to load Web Inspector once the application starts.
Currently when I hit Run on Xcode, the app loads and I setTimeout
on my first function so I can rush over to Safari and attach the Web Inspector on that page.
I'd much prefer to remove this step and add an automated step that would load the Web Inspector directly.
Any other solutions?
You'll need to go to Settings > Advanced and check the Show Debug Menu option. Then you'll see the option to open the web inspector for the Simulator right from that menu. With the Web Inspector open, you can debug inside the Simulator just like you could right in a desktop browser with DevTools.
Enable the Develop MenuChoose Safari > Preferences, and click Advanced. At the bottom of the pane, select the “Show Develop menu in menu bar” checkbox. Choose Develop > Show Web Inspector.
Inspect the page. In the Safari on your Mac, on the Safari menu bar, choose the "Develop" menu. Scroll to the iOS Simulator option. Select the page for debugging.
This is a partial solution. This opens the debug window of Safari with one click which is a lot better but not automatic.
Open Script Editor
on your mac (Command + Space Bar and type in Script Editor)
Paste in this code:
-- `menu_click`, by Jacob Rus, September 2006 -- -- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}` -- Execute the specified menu item. In this case, assuming the Finder -- is the active application, arranging the frontmost folder by date. on menu_click(mList) local appName, topMenu, r -- Validate our input if mList's length < 3 then error "Menu list is not long enough" -- Set these variables for clarity and brevity later on set {appName, topMenu} to (items 1 through 2 of mList) set r to (items 3 through (mList's length) of mList) -- This overly-long line calls the menu_recurse function with -- two arguments: r, and a reference to the top-level menu tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬ (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu))) end menu_click on menu_click_recurse(mList, parentObject) local f, r -- `f` = first item, `r` = rest of items set f to item 1 of mList if mList's length > 1 then set r to (items 2 through (mList's length) of mList) -- either actually click the menu item, or recurse again tell application "System Events" if mList's length is 1 then click parentObject's menu item f else my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f))) end if end tell end menu_click_recurse menu_click({"Safari", "Develop", "IOS Simulator", "index.html"})
Once the simulator has opened, click run on your script (you might need to allow the script editor in the settings the first time).
(Optional) You can save your the scripts as an app so that you don't have to have the script editor open.
(this answer is a more detailed version of Galatin's previous answer)
It's mid-2014 and there's still no elegant solution to this that I know of, but I like the idea of adding a short pause with setTimeout
to your app's init code. If adding a setTimeout
call isn't possible, you can also issue window.location.reload()
from the Safari console to restart your application with the benefit of full debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With