Debugging JavaScript on Android

I've been messing around with the Android emulator, particularly with its browser. Debugging just JavaScript wasn't well covered in the documentation, and I spent a little while getting it set up. I wanted to publish it here so it shows up in others' web searches -- I'll look into adding some of this to the official docs at work.

Anyway, to get you started: You can use either an actual Android device or an emulator. Install the Android SDK.

Then, you can use the Android Debug Bridge to connect to your device or emulator.

The key thing to note is that browser debug output will be tagged with WebCore. So, if you're only interested in browser debug output, start adb filtering debug output for everything but those tags. The command line is:
adb logcat WebCore:V *:S
Which means "show all debug output tagged with WebCore, and silence everything else" (see their documentation for more information).

You can do some sniffing around by looking at the window object in the browser:
var terms = [];
for (key in window) {
terms.push(key + ': ' + window[key] );
}
terms.sort();
for (var i = 0; i < terms.length; i++) {
document.write('<p>' + terms[i] + '</p>');
}
You'll notice a bunch of goodies in there (and a few interesting ones I'll investigate later). But, particularly, you'll notice a reference to window.console. Loop over that and you'll see:



Turns out it there's a console object with a subset of the methods from Firebug's console, though they just take a single string for the argument (not multiple arguments). The method names all produce debug output at the "D" level. So, this code:
console.error('1');
console.info('2');
console.log('3');
console.warn('4');
Produces this output:
D/WebCore (  165): Console: 1 line: 0 source: http://...
D/WebCore ( 165): Console: 2 line: 0 source: http://...
D/WebCore ( 165): Console: 3 line: 0 source: http://...
D/WebCore ( 165): Console: 4 line: 0 source: http://...
In addition, any JavaScript errors will also show up in the output. Good stuff.

Now you know.

 

A new day

The day before my birthday, Dave and I ran to catch a bus from Madison to Chicago. We were off to Union Station to catch a train to New York, where we were going to couch surf for a week over spring break. It was 2004. Crossing into Illinois, the ground was covered with patches of snow, and the street corners with political signs. It was days before the Democratic Senate primary. I remember the simple blue signs that read "Obama" in white serif, probably the first time I'd heard the name. He went on to easily defeat Alan Keyes (who I remember talking to in the lounge of my dorm previously).

It's now just a few months short of five years later. I'm on my couch in San Francisco (where I never expected to live), watching Obama take the oath of office to become the President of the United States.

Life is unpredictable. And that's awesome.