[英]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.