如何在Android上调试JavaScript? [英] How can I debug javascript on Android?

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

问题描述

我正在研究涉及拉斐尔的项目。原来,它在Android上无效。它在iPhone上



如何在Android浏览器上调试某些东西?这是WebKit,所以如果我知道这个版本,那么将会调整它的那个完整的版本的WebKit产生相同的结果?

解决方案

更新:远程调试



以前,控制台日志记录是在Android上调试JavaScript的最佳选择。现在,通过Chrome for Android远程调试,我们可以利用Android上的Chrome for Desktop Developer Tools的所有优点。查看 https://developers.google.com/chrome-developer-tools / docs / remote-debugging 获取更多信息。






更新:JavaScript控制台



您还可以在URL栏中导航到about:debug,以激活最近的Android设备的调试菜单和JavaScript错误控制台。您应该在浏览器的顶部看到SHOW JAVASCRIPT控制台。



目前在Android 4.0.3(Ice Cream Sandwich)中,logcat输出到浏览器频道。所以您可以使用 adb logcat浏览器过滤:* *:S






原始答案



您可以使用内置的控制台 JavaScript对象打印日志消息,您可以使用 adb logcat 查看

 控制台。错误('1'); 
console.info('2');
console.log('3');
console.warn('4')

生成此输出:

  D / WebCore(165):控制台:1行:0来源:http:// ... 
D / WebCore ):控制台:2行:0来源:http:// ...
D / WebCore(165):控制台:3行:0来源:http:// ...
D / WebCore (165):控制台:4行:0来源:http:// ...

确定WebKit的版本



如果键入 javascript:alert(navigator.userAgent)在位置栏中,您将看到列出的WebKit版本,例如



在Chrome中:
Mozilla / 5.0 (Windows; U; Windows NT 5.1; en-US)AppleWebKit / 532.2(KHTML,像Gecko)Chrome / 4.0.221.6 Safari / 532.2



<在Android模拟器上
Mozilla / 5.0(Linux; U; Android 1.6; en-us; sdk Build / DRC76)AppleWebKit / 528.5 +(KHTML,像Gecko)版本/ 3.1.2 Mobile Safari / 525.20.1



NB



不属于Safari版本的WebKit在版本号后面有一个+,它们的版本号通常高于最新发布的WebKit版本。所以,例如,528+是一个非官方的WebKit构建,比作为Safari 3.1.2的一部分发行的525.x版本更新。


I'm working on a project that involves Raphaeljs. Turns out, it doesn't work on Android. It does on the iPhone.

How the heck to I go about debugging something on the Android browser? It's WebKit, so if I know the version, will debugging it on that full version of WebKit produce the same results?

解决方案

Update: Remote Debugging

Previously, console logging was the best option for debugging JavaScript on Android. These days with Chrome for Android remote debugging, we are able to make use of all the goodness of the Chrome for Desktop Developer Tools on Android. Check out https://developers.google.com/chrome-developer-tools/docs/remote-debugging for more information.


Update: JavaScript Console

You can also navigate to about:debug in the URL bar to activate the debug menu and the JavaScript error console with recent Android devices. You should see SHOW JAVASCRIPT CONSOLE at the top of the Browser.

Currently in Android 4.0.3 (Ice Cream Sandwich), the logcat outputs to the browser channel. So you can filter using adb logcat browser:* *:S.


Original Answer

You can use the built in console JavaScript object to print log messages that you can review with adb logcat.

console.error('1');
console.info('2');
console.log('3');
console.warn('4')

Produces this output:

D/WebCore (  165): Console: 1 line: 0 source: http://...
D/WebCore (  165): Console: 2 line: 0 source: http://...
D/WebCore (  165): Console: 3 line: 0 source: http://...
D/WebCore (  165): Console: 4 line: 0 source: http://...

Determining the version of WebKit

If you type javascript:alert(navigator.userAgent) in the location bar you’ll see the WebKit version listed e.g.

In Chrome: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome/4.0.221.6 Safari/532.2

On Android Emulator Mozilla/5.0 (Linux; U; Android 1.6; en-us; sdk Build/DRC76) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1

N.B.

Versions of WebKit that are not part of a Safari release have a + after the version number, and their version number is generally higher than the latest released version of WebKit. So, for example, 528+ is an unofficial build of WebKit that is newer than the 525.x version that shipped as part of Safari 3.1.2.

这篇关于如何在Android上调试JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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