android模拟器中的console.log浏览器

发布于 2024-09-28 02:09:28 字数 57 浏览 6 评论 0原文

如何使用 Android 模拟器查看网站的 console.log 消息?

How to see console.log messages of a website using android emulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

樱娆 2024-10-05 02:09:28

来自 Rich Chetwynd 的短文“Android 浏览器上的 Javascript 调试”。

您可以从 Android 设备或模拟器记录 JavaScript 错误和控制台消息。为此,您首先需要在实际设备上安装Android SDK和USB驱动程序并启用USB调试。

要检查设备是否正确连接,您可以从 Android SDK 工具目录运行以下命令,您应该会在列表中看到一个设备

c:\android sdk..\platform-tools\adb devices

然后,您可以使用 Android 调试桥来过滤调试消息,以便通过运行以下 cmd 只看到与浏览器相关的消息。

c:\android sdk..\platform-tools\adb logcat browser:V *:S

默认情况下,日志会写入标准输出,因此您将看到任何写入 cmd 窗口的 Javascript 错误或 console.log 消息等。

更多详细信息:Logcat CLI 工具文档

From Rich Chetwynd's short article "Javascript debugging on Android browser".

You can log javascript errors and console messages from your Android device or emulator. To do this you first need to install the Android SDK and USB drivers and enable USB debugging on the actual device.

To check if the device is connected correctly you can run the following cmd from your Android SDK tools directory and you should see a device in the list

c:\android sdk..\platform-tools\adb devices

You can then use the Android Debug Bridge to filter debug messages so that you only see browser related messages by running the following cmd.

c:\android sdk..\platform-tools\adb logcat browser:V *:S

By default the log is written to stdout so you will see any Javascript errors or console.log messages etc written to the cmd window.

Further details: Logcat CLI tool docs.

夜巴黎 2024-10-05 02:09:28

在 chrome 上打开此网址

chrome://inspect

Open this url on your chrome

chrome://inspect

久随 2024-10-05 02:09:28

如果您使用 ADT 插件Eclipse 启动模拟器,您将直接在 LogCat 视图下看到所有 JavaScript 控制台日志:

Window -> Show View -> Android -> LogCat

If you have started the emulator from Eclipse with the ADT plugin, you will see all JavaScript console logs directly under the LogCat view :

Window -> Show View -> Android -> LogCat
明明#如月 2024-10-05 02:09:28

如果您使用的是Android Studio;您可以打开 Logcat (Alt+6) 并过滤: :CONSOLE

仅过滤 :CONSOLE (而不是 INFO:CONSOLE)显示所有类型的控制台消息(包括 ERROR、WARN 等)。

If you are using Android Studio; you can open your Logcat (Alt+6) and filter for: :CONSOLE

Filtering for only :CONSOLE (rather than INFO:CONSOLE) will display all types of console messages (including ERROR, WARN, etc).

会傲 2024-10-05 02:09:28

你可以临时添加一些 JavaScript,就像……

var console = {
    log: function(msg) { alert(msg); }
};

丑陋极了,但它确实有效。

You could add some JavaScript temporarily like...

var console = {
    log: function(msg) { alert(msg); }
};

Ugly as hell, but it works.

温馨耳语 2024-10-05 02:09:28

我使用以下代码劫持了 console.log:

function logManager() {
    var self = this;

    self.init = function () {
        console.log('logmanager initialized');
        var old = console.log;
        self.logger = document.getElementById('log');
        console.log = function (message, options) {
            if (typeof message == 'object') {
                self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />' + self.logger.innerHTML;
            } else {
                self.logger.innerHTML = message + '<br />' + self.logger.innerHTML;
            }
        }
    }
    self.toggleLogVisibility = function () {
        return $(self.logger).toggle();
    };
}

并在您的 html 中使用您自己的样式(绝对右上角是我使用的)

<div id="log" class="log">
    Application loaded...
</div>

并在您的 jscript 中使用它(在加载的页面上运行此代码,因为日志元素必须存在)

document.lmgr = new logManager();
document.lmgr.init();

I hijacked the console.log using this code:

function logManager() {
    var self = this;

    self.init = function () {
        console.log('logmanager initialized');
        var old = console.log;
        self.logger = document.getElementById('log');
        console.log = function (message, options) {
            if (typeof message == 'object') {
                self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />' + self.logger.innerHTML;
            } else {
                self.logger.innerHTML = message + '<br />' + self.logger.innerHTML;
            }
        }
    }
    self.toggleLogVisibility = function () {
        return $(self.logger).toggle();
    };
}

And consume it like so in your html with your own styling (absolute top right is what I used)

<div id="log" class="log">
    Application loaded...
</div>

And in your jscript (run this on page loaded as the log element has to exist)

document.lmgr = new logManager();
document.lmgr.init();
灯角 2024-10-05 02:09:28

命令 - 从模拟器获取日志

adb -e logcat 

adb.exe 可以在 $your_installation_path$\android sdk\platform-tools 找到

更详细的信息
https:// learn.microsoft.com/ru-ru/xamarin/android/deploy-test/debugging/android-debug-log?tabs=windows

Command - get log from the emulator

adb -e logcat 

adb.exe can be found at $your_installation_path$\android sdk\platform-tools

more detailed
https://learn.microsoft.com/ru-ru/xamarin/android/deploy-test/debugging/android-debug-log?tabs=windows

随遇而安 2024-10-05 02:09:28

如果由于 zsh 导致无法运行 adb logcat browser:V *:S,则需要运行 noglob adb logcat browser:V *:S。理由: https://github.com/ohmyzsh/ohmyzsh/issues/2901

If you cannot run adb logcat browser:V *:S because of zsh, you need to run noglob adb logcat browser:V *:S. Rationale: https://github.com/ohmyzsh/ohmyzsh/issues/2901

╭⌒浅淡时光〆 2024-10-05 02:09:28

如果你正在运行 React Native,那么在你运行它的 VSC 中: npm start ...你可以看到 LOG ...它将输出你放入 Console.log 的内容,交替在 WEB 和常规控制台中运行它。 log ... F12,在检查器中...通常的 Web 开发...

If you are running React native, then in VSC where you RAN it: npm start ... you can see LOG ... it will output what every you put into Console.log, alternatvely run it in the WEB, and regular console.log ... F12, in inspector... the usual web development...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文