safari snippets

How to Debug Phonegap Applications With Safari's Remote Debugger

Tagged phonegap, safari  Languages 
  1. On your iPhone/iPad: Enable Web Inspector . Open “Settings” → “Safari” → “Advanced”.
  2. On your desktop/laptop: Enable Developer tools in Safari. Open “Preferences” → “Advanced” check “Show Develop menu in menu bar”.
  3. Connect your iPhone via USB to your desktop/laptop.
  4. Start the application on your iPad/iPhone via XCode.
  5. On your desktop/laptop: Open the Safari Web Inspect debugger. Go to “Preferences” → “Your phone” → “index.html”.

You can automate the last step by using applescript to open Safari's Web Inspector.

Note: Use CMD+R to reload index.html.

How to Open Safari's Web Inspector With Applescript to Debug a Phonegap App

Tagged safari, web-inspector  Languages applescript

This trick will save years of your life. This applescript will make Safari's Web Inspector connect to a Phonegap application running on my iPhone that was started through XCode:

#!/usr/bin/osascript

set device_name to "Christian Hellsten iPhone"
tell application "Safari"
    activate
    tell application "System Events"
        try
            click menu item "index.html" of menu device_name of menu item device_name of menu "Utvecklare" of menu bar item "Utvecklare" of menu bar 1 of application process "Safari"
        end try
    end tell
end tell

Save the file, as e.g. open-web-inspector.applescript, then execute it:

chmod +x open-web-inspector.applescript
./open-web-inspector.applescript

For English version, change "Utvecklare" to "Develop".

Troubleshooting

  1. Error -1719 most likely means you need to enable assistive access for iTerm or whatever app you're running the script from.
  1. Error -10810 means "bad luck" in Applescript. Try restarting the computer.

If all else fails, run the script using the Applescript Editor. Also see, this script.

Tested on OSX Yosemite.