Set a logpoint - Firefox Developer Tools 编辑

Sometimes you want to view a value in your code but you don't want to pause execution. Rather than sprinkle console.log() statements throughout your code, you can use a special type of breakpoint, the logpoint. Logpoints print a message to the Console panel instead of pausing code execution.

The logpoint is especially useful in cases where breaking the execution breaks testing procedures, such as when you are debugging popup windows, or executing focus-related logic.

To create a logpoint:

  1. Right click on a line number in the Debugger panel and pick Add log action from the context menu.

  2. Create an expression inline. The result is logged in the console panel every time the line with the logpoint executes. You can use any variable or function available in the current scope.

Working with logpoints

When you set a logpoint, the indicator is purple, rather than the blue of an unconditional breakpoint or the orange of a conditional breakpoint.

You can view the list of logpoints in the Breakpoints side panel.

When execution hits a logpoint, the message you have defined is logged to the console. You can make it easier to see the message by opening a split console under the debugger. (Either press Esc or select the ellipsis menu (...) and then click Show Split Console.)

When should you use logpoints?

  • When you want to know that a specific line in your code has executed, but you don’t want to break code execution, set a logpoint.
  • Logpoints are useful to log the value of a variable at a specific point in the code. It’s faster than changing the underlying source code itself to add calls to the console.log method.
  • If you need to execute additional logic related to the source code and you can’t change the source code itself, you can use a logpoint.
  • Note that you can use logpoints with source-mapped code, as well as with your unmapped source files.

See also

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:95 次

字数:3819

最后编辑:7 年前

编辑次数:0 次

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