Debugging JavaScript on Internet Explorer Mobile

I was recently asked how I debug JavaScript code executing on Internet Explorer Mobile. First things first you need to configure Internet Explorer Mobile to show JavaScript Errors. As noted here you need to:

Change the Registry setting “HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main” and Create a new DWORD key under Main with the name “ShowScriptErrors“. Set dword value of 1

There are (at least) two ways to change registry settings on a Windows Mobile device/emulator. Firstly you can use the Remote Registry Editor (Start|Microsoft Visual Studio 2005|Visual Studio Remote Tools) that comes with Visual Studio. Alternatively you can install a registry editing application on the device, for example PHM Registry Editor.

Once you’ve restarted Internet Explorer Mobile it should start showing JavaScript errors. This and good old alert() are really all the tools you have at your disposal to do debugging. There is no way (that I know off) to attach to the JavaScript engine running on the Windows Mobile device and do remote debugging. In fact this is a problem for most if not all embedded browsers. 

One thing you can do is leverage XMLHttpRequest (XHR) to log messages to a remote server, sometimes useful when you need to log more information than will easily fit in an alert() dialog box on a cramped Windows Mobile display.

Advertisements