如何在 Chrome 或 Safari 中的缩小 JS 函数上设置断点?
我想在 Chrome 或 Safari JavaScript 调试器的“Cart.add”函数中设置断点。问题是,这个函数是在一个大的缩小的 JS 文件中定义的,并且它本身不存在于一行中。
一些文档说基于 WebKit 的调试器支持调试控制台中的“break”或“debug”命令,但这些命令似乎不适用于较新版本的调试器。
在 JS 文件的该行上设置断点也不起作用,因为该行上有很多函数。
有什么建议吗?
I'd like to set a breakpoint in a "Cart.add" function in the Chrome or Safari JavaScript debuggers. Problem is, this function is defined in a large minified JS file, and doesn't exist on a line by itself.
Some documentation says that the WebKit-based debuggers support "break" or "debug" commands in the debug console, but those don't seem to work in newer versions of the debugger.
Setting a breakpoint on that line of the JS file doesn't work either, since there are lots of functions on that line.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在Chrome中,当您打开
脚本
选项卡时,您可以通过单击{}
button(“ pretty Print”)来假装所选文件。之后,您可以找到自己的行并设置断点。页面刷新后,该代码将保持利用中的断点。In Chrome when you open
Scripts
tab you can prettify selected file by clicking on{ }
button ("Pretty print") at the bottom. After that you can find your line and set a breakpoint. The code will remain prettified with breakpoints in place after a page refresh.debugger
语句可能就是您正在寻找的内容。break
语句用于退出循环和switch
语句,与调试无关。真正的解决方案是首先不要干扰你的代码:)
The
debugger
statement is probably what you're looking for.The
break
statement is for exiting loops andswitch
statements and has nothing to do with debugging.The real solution though is to not bugger your code in the first place :)
1) 错误消息应该为您提供指向源代码的链接
来源选项卡。单击该链接即可看到转译的代码。
2)点击源代码底部的“{ }”图标
“源”选项卡可格式化已转译的代码,以便于调试。
3)在失败的行上设置断点。
4) 重现
又出问题了。这次应该在之前的断点处中断
发生错误。
5) 检查局部变量和调用堆栈
确定到底出了什么问题。
1) The error message should give you a link to the source code in the
Sources tab. Click on that link to get taken to the transpiled code.
2) Click the "{ }" icon at the bottom of the source code in the
Sources tab to format the transpiled code for easier debugging.
3)Stick a breakpoint at the line that is failing.
4) Reproduce the
problem again. This time, it should break at the breakpoint before
the error occurs.
5) Examine the local variables and call stack to
determine what exactly is going wrong.
对于 Chrome 用户,您需要在实验功能中启用自动漂亮打印。
设置断点现在应该可以工作了。
For chrome users, you'll want to enable automatic pretty print in the experimental features.
setting your breakpoint should work now.
如果您已保存网页,则使用 jsbeautifier.org 来美化您的 js 文件,该文件会格式化您的整个脚本。然后将你的js内容替换为美化后的版本。从这里你可以轻松调试你的 JS
If you have saved the webpage then beautify your js file using jsbeautifier.org which formats your entire script. Then replace your js content with the beautified version. From here you can debug your JS easily