Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging javascript on Android tablets/phones?

How do I enable the debug view like I can in Safari on iOS? I simply need to see if a Xoom that I'm testing a page on is generating javascript errors. I was trying to find how to enable the dev tools in the Android browser like I do for iOS but can't seem to locate it.

like image 637
Geuis Avatar asked Apr 19 '11 22:04

Geuis


People also ask

Can you debug JavaScript?

JavaScript DebuggersBuilt-in debuggers can be turned on and off, forcing errors to be reported to the user. With a debugger, you can also set breakpoints (places where code execution can be stopped), and examine variables while the code is executing.


2 Answers

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.

like image 64
Mauvis Ledford Avatar answered Sep 20 '22 03:09

Mauvis Ledford


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.

like image 37
KushalP Avatar answered Sep 22 '22 03:09

KushalP