简体   繁体   English

在Android上调试javascript时如何查看断点(并查看错误行号)?

[英]How can I hit breakpoints (and see error line numbers) when debugging javascript on Android?

I'm trying to follow these instructions for debugging android javascript. 我正在尝试按照这些说明调试android javascript。

I am aware of How can I debug javascript on Android? 我知道如何在Android上调试javascript? , but it's not clear to me how (or if) I can hit breakpoints - either using Chrome on the Android device, or the Android browser. ,但我不清楚如何(或者如果)我可以点击断点 - 在Android设备上使用Chrome或Android浏览器。

I can see and 'inspect' the device OK: 我可以看到并“检查”设备OK:

在此输入图像描述

But breakpoints don't get hit, nor can I see line numbers on the errors in the console: 但断点不会受到影响,也无法在控制台中看到错误的行号:

在此输入图像描述

Between these two problems, I'm not getting much useful information from the debugging experience! 在这两个问题之间,我从调试体验中获得的信息并不多! I have tried going to 'about:debug' in the android browser, and do see the debug options appear. 我已经尝试在android浏览器中进行'about:debug',并且看到调试选项出现了。

I will add that the js I am debugging works fine in the latest Chrome on the same Android device. 我将补充说,我正在调试的js在同一Android设备上的最新Chrome中工作正常。

First off, it seems like there are a bunch of syntax errors that may be preventing mustache.js from executing at all - see if you can take care of those first. 首先,似乎有一堆语法错误可能会阻止mustache.js执行 - 看看你是否可以先处理它们。

I'd try setting a breakpoint on the next line down - line #9 - to see if anything in that IIFE is running at all. 我试着在第9行下一行设置一个断点,看看那个IIFE中是否有任何东西在运行。

Assuming you are using a module bundler (such as Webpack) in development (based on port 8080 in your screenshot), most likely the code you're trying to debug is executed via eval . 假设您正在开发中使用模块捆绑器(例如Webpack)(基于屏幕截图中的端口8080),您尝试调试的代码很可能是通过eval执行的。 In which case by the time you can see it in the devtools, it has already run. 在这种情况下,当你可以在devtools中看到它时,它已经运行了。

You can either use the debugger statement in your code, or running in production mode - where there's a real script file being executed. 您可以在代码中使用debugger语句,也可以在生产模式下运行 - 其中有一个真正的脚本文件正在执行。 In both cases, you should attach the remote debugger first, and only then navigate to your page (or refresh it). 在这两种情况下,您应首先连接远程调试器,然后才能导航到您的页面(或刷新它)。

I have now tried the same thing again, and this time didn't experience the problem. 我现在又尝试了同样的事情,这次没有遇到问题。 Unfortunately I can't put my finger on what the problem was exactly, as due to my dev machine dying I am running a new windows 10 installation, and potentially a different version of the Android SDK and ADB. 不幸的是,我无法确定问题的确切原因,因为我的开发机器死机,我正在运行新的Windows 10安装,可能还有不同版本的Android SDK和ADB。 The phone and android browser haven't changed. 手机和Android浏览器没有改变。

Anyway, I can now set and hit breakpoints as I'd expect: 无论如何,我现在可以像我期望的那样设置和命中断点:

在此输入图像描述

I also get better error descriptions and line numbers: 我也得到更好的错误描述和行号:

在此输入图像描述

FWIW, the only problem that needed fixing was changing some 'let' declarations to 'var'. FWIW,唯一需要修复的问题是将一些'let'声明改为'var'。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 VS Code 中调试 Node JS 应用程序时没有命中断点 - Breakpoints are not hit when debugging Node JS app in VS Code 当我在JavaScript文件中点击断点时,下拉列表停留在屏幕上。 为什么? - Dropdown is staying on the screen when I hit breakpoints in JavaScript files. Why? javascript-如何通过在 Chrome 中调试在一个 if 语句中查看每个条件的结果? - javascript-how can I see result of every condition in one if statement By Debugging in Chrome? 如何在JavaScript中存储已解析的YAML文件的行号? - How can I store line numbers for a parsed YAML file in JavaScript? 如何在 Android 应用程序的 WebView 中查看 Javascript 错误? - How can I see Javascript errors in WebView in an Android app? HTML5历史记录:如何查看弹出的URL(即单击“后退”按钮时所处的页面) - HTML5 history: how can I see the URL that was popped (ie, the page we were on when we hit the back button) 在 TypeScript 中写入时,如何看到 Deno 转译的 javascript? - How can I see Deno transpiled javascript when writing in TypeScript? 在调试iOS网页时,Weinre是否可以设置javascript断点 - Is it possible with Weinre to set javascript breakpoints when debugging iOS webviews WebStorm中的断点不适用于JavaScript调试 - Breakpoints in WebStorm not hitting for JavaScript debugging 调试时如何查看document.write的输出? - How can I see the output of document.write while debugging?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM