31

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?

sonjz
  • 4,870
  • 3
  • 42
  • 60

3 Answers3

3

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)

Dev01
  • 13,292
  • 19
  • 70
  • 124
  • For a lazier solution, try going to `System Preferences > Keyboard > Shortcuts` and add an "App Shortcut" for Safari for the menu title `localhost` or whatever your URL looks like in the Develop menu. – Nick Farina Apr 29 '16 at 22:59
2

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.

sherb
  • 5,845
  • 5
  • 35
  • 45
1

1) Inside your OnDeviceReady handler add debugger;

onDeviceReady: function() {
    debugger;
    // the rest of your device ready code
}

2) Run the application via xcode or cmdline.

3) Attach the debugger via Safari->Develop->Simulator->Appname -> index file

4) Open the console view of safari and enter:

Window.location = "";

5) The app will reload and the debugger will attach on the first line of onDeviceReady().

6) Debug as normal.