在Android平板电脑/手机上调试javascript? [英] Debugging javascript on Android tablets/phones?

查看:817
本文介绍了在Android平板电脑/手机上调试javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS上的Safari中启用调试视图?我只需要看看我正在测试一个页面的Xoom是否正在生成JavaScript错误。我试图找到如何在Android浏览器中启用开发工具,就像我为iOS,但似乎找不到它。

解决方案

我曾经在过去的一个Android应用程序,其中java开发人员设置它警告JavaScript错误 - 抓到一个额外的bug,我们没有抓住在iOS版本,因为它。所以,如果你有访问java层,我会检查出来。我问他他做了什么具体的,他说:
有一个回调从WebView类,让我知道当JS代码引发错误,我实现回调显示一个android对话框。



有两个解决方案,其他的想法在这上面,我用于调试(ios / android)。这些对于您无法访问内置控制台的游戏中的嵌入式网络视图特别有用:



1) Weinre 一个仍然是测试版,但功能,远程调试器。它会给你一个虚假的检查器在桌面上,你可以查询/看到远程设备上的错误。有一个整个dom检查器和任何东西。开发它的人也很灵敏。



2)我写了一个javascript日志函数,命中我的服务器错误日志。只是尾部你的日志文件,你很好去。我的javascript函数看起来像这样:

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

这样我可以接受任何数量的参数。
我收到这个请求的php页面看起来像这样:

 #确保这不能用于生产
if(strpos($ GLOBALS ['HTTP_HOST'],'devboxhostname')< 0)die(':(');
error_log($ _ GET ['m']);
希望未来移动开发人员将有更好的调试工具。

$

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.

解决方案

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平板电脑/手机上调试javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆