A couple of debugging tricks…

Examine variables in a running app

You can examine the value of global variables in a running app on any device, without needing to have a debugger hooked up.

Simply enter this into the URL bar:

javascript:alert(a)

This will display the value of a in a message box.

You can also use this to call functions:

javascript:alert(window.innerHeight)

You can enter any valid JavaScript code and it will execute in the current context.

Wow.

View JavaScript errors on Android devices

It’s not easy to see JavaScript errors on Android devices, especially older ones. To do this, you will need to have the Android SDK installed.

Start the simulator or connect your device in debug mode.

Open up a command window and type

adb logcat

You will see a stream of output with all the messages from the device or simulator. The error message will look something like this:


D/dalvikvm(  284): GC_FOR_MALLOC freed 34 objects / 2096 bytes in 212ms
E/browser (  284): Console: TypeError: defineProperty is not supported on DOM Ob
jects http://www.nsbasic.com/i/Order/nsb/hfunc.js:1926