Debugging javascript on Android tablets/phones? Debugging javascript on Android tablets/phones? android android

Debugging javascript on Android tablets/phones?


I've worked on an Android app in the past where the java developer set it to alert JavaScript errors - caught an extra bug that we didn't catch in the iOS version because of it. So, if you have access to the java layer, I'd check that out. I asked him what he did specifically and he said: "There's a callback from the WebView class that lets me know when the JS code throws an error. I implemented that callback to display an android dialog."

There's two solutions other ideas on top of this that I use for debugging (ios/android). These are especially useful for embedded web views in games where you don't have access to the built-in console:

1) Weinre a still beta, but functional, remote debugger. It'll give you a faux inspector on your desktop that you can query / see errors on your remote device with. Has a whole dom inspector and anything. The guy that develops it is pretty responsive, too.

2) I write a javascript log function that hits my servers error log. Just tail your log file and you're good to go. My javascript function looks something like this:

function hlog(){    var s = Array.prototype.slice.apply(arguments).join('ΒΆ');    document.createElement('img').src = 'http://yourdevbox/debugger/?m=' + encodeURIComponent(s);}

That way I can take any number of arguments.My php page that recieves this request looks like this:

# ensure this can't be used in production if (strpos($GLOBALS['HTTP_HOST'], 'devboxhostname') < 0) die(':(');error_log($_GET['m']);

Hopefully in the future, mobile devs will have way better debugging tools.


Android doesn't (currently) have a WebInspector like Chrome/Chromium does.

You can still look at any console.log() messages fired under window.console in logcat.

Source: http://developer.android.com/guide/webapps/debugging.html

Also, whilst Firefox 4 is available for Android, Firebug currently isn't supported on the mobile version of the browser.


type about:debug into the url field and validate, a javascript console will then be available (same method to remove it)

a bit more on this page: https://android.stackexchange.com/questions/5999/android-browsers-aboutdebug-what-do-those-settings-do