Debugging PhoneGap Apps with the Chrome Dev Tools

PhoneGap/Cordova is a really cool framework for making mobile apps, but there is a dark side that isn’t talked about enough. How to debug your apps? If you are writing any kind of non-trivial app, you will need something more than console.log and a lot of patience to debug your app. A partial solution to this issue is the Chrome Dev Tools. I say partial because apps which rely heavily on PhoneGap features won’t work in Chrome, but if your app is more like a mobilized web site, you may benefit from this info.

I am assuming that you already have an app or two that you want to debug, so I won’t cover anything about building PhoneGap apps here. I am just going to cover setting things up so you can use Chrome’s Dev Tools to debug your app. This is the Windows 7 version of the instructions. I will post the Mac version in a day or two.

Directory Setup
All of my PhoneGap apps share the same parent directory, “Repo”. So what I propose to do is, make Repo a web site. Now, some people I’ve talked to prefer to make each individual app its own website. If you do too, this technique will still work for you, just change the location of the website’s directory.

  1. Begin by starting Internet Information Services 7 aka IIS7.Mine’s just happens to be on the start page. Normally it would be under Adminstrative Tools.

  2. On the left side, expand your computer name by clicking the disclosure triangle (my computer’s name is TROYMILESF42B).
  3. Expand the Sites list too.
  4. Right click on Sites.

  5. Click Add Web Site…
  6. Give the site a name, mines is “Repos”.
  7. Select an Application Pool, I chose ASP.NET v4.0.
  8. Select the path to your root folder.

  9. If your machine runs with security, you may need to give it a user account to run against.

  10. I highly recommend setting the port to something other than port 80, I am using 8088.
  11. Make sure the “Start Web site immediately” check box is set.
  12. Click OK.
  13. Using Chrome, navigate to your website.

  14. Enter Ctrl+Shift+I to open Chrome’s developer’s tools.
  15. Click on the Sources tab, then the click the disclosure arrow on the top left side to show the source files.
  16. Double click a file name to open it.

  17. To set a break point simply click a line number along the left side. Click it again to disable the break point. Right click it and click, Remove breakpoint, to remove it.

This is Great but…
This is all great but we still have a problem. We no longer have a “deviceready” event, so this may break your code. For example, my compass app won’t work without the PhoneGap enhancements to the navigator object. But strictly HTML sites will be good to go now.

I am still working on a partial solution to the “deviceready” issue, but it is not ready yet. It is suffice to say that it just mocks the event and places some test values data into the navigator object. 

One thought on “Debugging PhoneGap Apps with the Chrome Dev Tools

  1. Phonegap is really cool…Which application let's you develop a cross-platform applications within minutes? There are many applications available, but phonegap is my favorite and I still suggest the developers to use it because of it's innumerable benefits.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s