HTC Android 设备和 adb logcat 上的 Javascript console.log()
我正在开发 HTML 中的应用程序,该应用程序从 Javascript 调用 console.log()
来在开发过程中向我提供有关网页代码中发生的情况的日志。
不幸的是,当我使用 adb logcat
命令检查日志时,我可以看到所有其他应用程序的输出,但看不到 JavaScript 代码的输出。我什至可以从网络浏览器中看到页面已加载的日志,但看不到在网络浏览器中执行的 JavaScript 代码的 console.log()
输出。
根据此页面 (http://developer.android.com/guide/webapps/debugging.html)它应该可以工作。
我正在 HTC WildFire 和 HTC Desire HD 上进行测试。
超过 6 个月后编辑
经过一段时间和使用不同设备(手机、电视、机顶盒、WebViews、UIWebViews...)的经验后,我的建议是进行远程日志记录 来自 JavaScript,而不依赖于 console.log() 或其他方法 - 查看图像加载的好技巧 此处。
不要错过此处的演示 希望这有帮助! 斯坦恩
I am developing the application in HTML which is calling the console.log()
from Javascript to provide me logs during the development about what happens in the web page code.
Unfortunately when I use the adb logcat
command to check logs I can see output from all other applications, but not the output from my JavaScript code. I can see even the log from web browser that the page is loaded, but not console.log()
output from my JavaScript code executed in the web browser.
According to information on this page (http://developer.android.com/guide/webapps/debugging.html) it should work.
I am testing on HTC WildFire and HTC Desire HD.
Edited after more then 6 months
After some time and experience with different devices (phones, TVs, set top boxes, WebViews, UIWebViews...) my advice is to do the remote logging from JavaScript and not relying on the console.log() or other methods - see the nice trick with the image loading here.
Do not miss the presentation here
Hope this helps!
STeN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 Android 2.3.3(大概从那时起)的默认浏览器中,您可以简单地使用内置的 javascript 控制台:
about:debug
并点击输入在顶部,您将看到一个标有“JavaScript 控制台”的栏。
In the default browser on Android 2.3.3 (and presumably from then on) you can simply use the built in javascript console:
about:debug
in the address bar and hit enterAt the top, you'll see a bar labeled "JavaScript Console".
我几乎只使用过三款不同的 HTC 手机,从未遇到过此问题。以下是一些需要检查的事项:
打开 USB 调试:
设置一个覆盖 onConsoleMessage() 的 WebChromeClient:
有关 onConsoleMessage() 的更多信息,请参见:http://developer.android.com/reference/android/webkit /WebChromeClient.html#onConsoleMessage(java.lang.String, int, java.lang.String)
有关调试的更多信息:http://developer.android.com/guide/webapps/debugging.html
过滤 adb logcat 的输出:
tag-name与 Log.x 中指定的字符串匹配
log-level 与您在调用 Log.x 时指定的日志级别相匹配 <---
与上述代码相关的示例:
这将显示匹配标签、Your-Application-Name 的所有 d 级别日志,并静默其他所有内容。
有关 adb 过滤的更多信息,请参见此处:
http://developer.android.com/guide/developing/tools/adb .html#logcat
希望有帮助!我知道这是对其他答案的一些总结,但事实是,它需要所有步骤才能使其发挥作用。 :)
I have been using three different HTC phones, almost exclusively, and have never had this issue. Here are a few things to check:
Turn on USB debugging:
Set a WebChromeClient that overrides onConsoleMessage():
More info on onConsoleMessage() here: http://developer.android.com/reference/android/webkit/WebChromeClient.html#onConsoleMessage(java.lang.String, int, java.lang.String)
More info on debugging in general here: http://developer.android.com/guide/webapps/debugging.html
Filter the output of adb logcat:
tag-name matches the string specified in Log.x
log-level matches the log level you indicated when calling Log.x <---
Example relating to code above:
This will show all d level logs for the matching tag, Your-Application-Name, and silence everything else.
More info on adb filtering here:
http://developer.android.com/guide/developing/tools/adb.html#logcat
Hope it helps! I know it was a bit of summarizing of the other answers, but, the fact is, it takes all of the steps to make it work. :)
我遇到了同样的问题,我通过执行以下操作解决了它:
1/ 当您初始化 webview 时,添加一个 javascript 桥接类:
2/ 创建带有日志函数的 JSBridge 类
3/ 在您的 javascript 中您现在可以调用
可能是对于你的问题来说有点矫枉过正,但你也可以用这个解决方案做更多的事情
I had the same problem, I solve it by doing the following:
1/ when you initialize your webview, add a javascript bridge class:
2/ create the class JSBridge with a log function
3/ in your javascript you can now call
Might be a bit overkill for your problem, but you can also do a LOT more with that solution
除了您的设备之外,Logcat 还会在设备上生成很多内容,因此您可能必须对其进行过滤。
如果您已标记日志输出,则可以尝试“grep”它。
例如:根据您的文章,输出应如下所示:
如果您使用该命令(假设您使用的是 Linux、Mac OS 或任何带有 grep 命令的其他操作系统),
它会将输出减少为这些引号内指定的关键字。如果您在输出中添加唯一标签,您还可以对其进行过滤,以便只获得您想要查看的内容。
将停止此 logcat 进程。
Logcat generates a lot of stuff on devices in addition to yours so you may have to filter this.
You can try to "grep" your log output if you've tagged it.
For example: acording to your article the output should look like:
If you use the command (assuming you are using a Linux, Mac OS or anything else with a grep command)
it will reduce the output to the keyword specified within these quotation marks. If you add a unique tag to your output you can also filter this so you get only things you want to see.
will stop this logcat process.
请参阅:如何使用 Eclipse 和 HTC Desire HD 在 PhoneGap 应用程序中显示 console.log() 输出?
您可以通过使用 远程调试 来解决这个问题.com" rel="nofollow noreferrer">jsconsole.com。
See this: How to display console.log() output in PhoneGap app using Eclipse and HTC Desire HD?
You can get around it by using remote debugging in jsconsole.com.
请尝试以下操作:
1) 打开设备选项卡并确保已选择/突出显示您已连接的设备。
2) 确保您的设备上启用了 USB 调试。为此,您需要执行以下操作:
Try the following:
1) Open the devices tab and make sure that the device you have connected is selected/highlighted.
2) Make sure USB Debugging is enabled on your device. Here is what you need to do for this: