Debugging javascript on Android tablets/phones?

前端 未结 7 1801
挽巷
挽巷 2021-01-11 10:06

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

7条回答
  •  庸人自扰
    2021-01-11 10:55

    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.

提交回复
热议问题