Reputation: 5090
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?
Upvotes: 31
Views: 3871
Reputation: 1
tell application "System Events"
tell process "Safari"
set frontmost to true
click menu item "App" of menu of menu item "iPhone 15 (Simulator)
iOS 17.0.1" of menu "Developer" of menu bar 1
end tell
end tell
Upvotes: 0
Reputation: 26
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.
Upvotes: 1
Reputation: 14149
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)
Upvotes: 3
Reputation: 6115
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.
Upvotes: 2