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
You can do some sniffing around by looking at the

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:
Now you know.
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 *:SWhich 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 = [];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
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>');
}
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://...In addition, any JavaScript errors will also show up in the output. Good stuff.
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://...
Now you know.
Comments:
<< Home
thanks! very very helpful. console.log, oh my! well, I got a application, small one, written with GWT, it uses canvas, and crashes android browser without any output. any idea how can I debug this?
Post a Comment
Subscribe to Post Comments [Atom]
<< Home
