如何在 Chrome 或 Safari 中的缩小 JS 函数上设置断点?

发布于 2024-12-04 08:26:06 字数 233 浏览 0 评论 0原文

我想在 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 技术交流群。

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

发布评论

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

评论(5

乄_柒ぐ汐 2024-12-11 08:26:07

在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.

暮凉 2024-12-11 08:26:07

debugger 语句可能就是您正在寻找的内容。

评估DebuggerStatement生成可能会允许实现在调试器下运行时导致断点。如果调试器不存在或不活动,则此语句没有明显的效果。

生产DebuggerStatementdebugger;评估如下:

  1. 如果实现定义的调试工具可用并已启用,则

    a.执行实现定义的调试操作。

    b.令 result 为实现定义的完成值。

  2. 其他

    a.设结果为(正常、空、空)。

  3. 返回结果。

break 语句用于退出循环和 switch 语句,与调试无关。

真正的解决方案是首先不要干扰你的代码:)

The debugger statement is probably what you're looking for.

Evaluating the DebuggerStatement production may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect.

The production DebuggerStatement : debugger ; is evaluated as follows:

  1. If an implementation defined debugging facility is available and enabled, then

    a. Perform an implementation defined debugging action.

    b. Let result be an implementation defined Completion value.

  2. Else

    a. Let result be (normal, empty, empty).

  3. Return result.

The break statement is for exiting loops and switch statements and has nothing to do with debugging.

The real solution though is to not bugger your code in the first place :)

孤芳又自赏 2024-12-11 08:26:07

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.

梦醒灬来后我 2024-12-11 08:26:07

对于 Chrome 用户,您需要在实验功能中启用自动漂亮打印。

启用自动Pretty print

设置断点现在应该可以工作了。

For chrome users, you'll want to enable automatic pretty print in the experimental features.

enabling automatic pretty print

setting your breakpoint should work now.

若水般的淡然安静女子 2024-12-11 08:26:07

如果您已保存网页,则使用 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

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