The poor state of Android JavaScript debugging

By | March 16, 2014

Cross-platform mobile web development is heating up and the the performance level is continuing to increase as new an more powerful devices are released. One of the allures to this style of mobile development is the single code base you can use across multiple platforms. With wrappers like Cordova and modern web frameworks you can get up and running super quick, but you incur a technical debt in debug time that you won’t know you need until it breaks in an unexpected way. It will break if you work on a sufficiently complex application.

When you start in cross-platform you’re probably thinking about hitting the most devices possible with the least amount of development time. Google reports, as of this posting, that Ice Cream Sandwich and KitKat account for 17.7% of Android installs (http://developer.android.com/about/dashboards). Those devices have it easy because they are coming with Chrome for Android installed. Chrome for Android features the future of debugging mobile web applications with the new remote debugger you can read about https://developers.google.com/chrome-developer-tools/docs/remote-debugging. That is wonderful for the future, but the other 82.3% of devices don’t get this new browser, and that means you don’t get those fancy new debugging features.

88294The first option for debugging on Android is a hosted JavaScript file that is served by a tool called Weinre. The quick way to give Weinre a try is to use the version hosted by PhoneGap at http://debug.phonegap.com. Just load up the script on that page in your app, but you’ll have to use Safari, Chrome didn’t work for me though it did for my colleague. Again poor planning for the extra Android debug efforts lead to confusion and short patience. From here you can see current CSS, DOM and execute JavaScript, but you can’t set any breakpoints. It is very slow, think slower to use than the Android ARM emulator is, and will cause frustration for developers.

Another option that you can use is jsHybugger which is an instrumentation library. This is the solution for proper JavaScript debugging, but the instrumentation does change your code when enabled and deployed to your device. I was personally met with race conditions when the JavaScript files were loaded in a large application and felt uneasy about relying on it for accurate debugging. We suffered from the same poor planning I am advising you don’t do in your project. By the time we needed to debug the app our patience was short, and we didn’t give it enough time or planning.

In the end, to debug your cross-platform mobile web application I would use a combination of both jsHybugger and Weinre. When you start your project and are thinking about all the speed of development improvements just don’t forget about debugging your program. You’ll want to allow for more time debugging your application on Android than you would on iOS. Eventually this won’t be as much of an issue, and it isn’t an issue at all of you only support Chrome for Android, but for now you’ll need to work with more than one debugging solution to deploy a successful cross-platform mobile web app.

3 thoughts on “The poor state of Android JavaScript debugging

  1. Sascha

    Hi Barrett,

    very interesting read! Can you provide us with a few code examples you were having race conditions with? That would be awesome. Many of our users debug their production code with jsHybugger (including thousands of lines of JavaScript), so there is really no need to feel uneasy about anything. I am confident that we can fix your issue. Thanks!

    Best regards,

    Sascha

  2. Barrett Sonntag Post author

    Hi Sascha, I wish I could but it’s all confidential, the app was using AMD and dozens of different files. I’m sure if we had the patience at the time we could have made better use of jsHybugger, your solution is really the only option out there for JavaScript breakpoints! Honestly, by the time we got to that point of needing to debug it we were burnt out and didn’t give it as good a chance as it needed. I updated the post with a bit more on my own short coming in that regard.

  3. Sascha

    Hi Barrett,

    ok got it, thanks for the info. We never had anyone raising an issue with race conditions before, but we will definitely have a close look at the way modules are loaded in AMD. Maybe you guys were onto something here.

    Best regards,

    Sascha

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.