简体   繁体   English

使用Chrome Web Inspector在行中间添加断点

[英]Adding a breakpoint in the middle of a line with Chrome Web Inspector

Say I have some JavaScript code like this: 说我有一些像这样的JavaScript代码:

function breakpointInside() { console.log("How do I add a breakpoint here?"); }
breakpointInside();

Assume I can't edit the source file. 假设我无法编辑源文件。 I would like to debug breakpointInside , but I cannot figure out how to add a breakpoint in the middle of the line. 我想调试breakpointInside ,但我无法弄清楚如何在行的中间添加断点。 In this example, it's trivial to step into the function, but assume it's a more complex script where this isn't as practical. 在这个例子中,步入函数是微不足道的,但是假设它是一个更复杂的脚本,这是不实际的。

Here are 2 related solutions 这是2个相关的解决方案

1) De-obfuscate Source 1)去混淆源

You can't put a breakpoint inside a line, but you can (in newer versions of Chrome) right-click on the script, select De-obfuscate Source , and put a breakpoint on the de-obfuscated version (which will have one statement on each line). 你不能在一行内放一个断点,但是你可以(在较新版本的Chrome中)右键单击脚本,选择De-obfuscate Source ,并在去混淆版本上放置一个断点(它将有一个语句)在每一行)。

2) Pretty Print 2)漂亮的打印

(based on comment by Nicolas) (根据尼古拉斯的评论)

In later versions of Chromium-based browsers, this function is called "Pretty print" and is available as a button at the left below the source code panel that looks like {} 在基于Chromium的浏览器的更高版本中,此功能称为“Pretty print” ,可在源代码面板左下方的按钮处显示,如{}

The comment by Nicolas Boisteault is the one to be used in latest versions of chrome. Nicolas Boisteault的评论是最新版Chrome中使用的评论。

In 2015 you can click the {} button called pretty print at the bottom left. 在2015年,您可以单击左下方名为pretty print的{}按钮。 – Nicolas Boisteault - Nicolas Boisteault

You can edit the source with Chrome DevTools live: simply double click on the source in the Scripts panel and add a line break before console.log. 您可以使用Chrome DevTools实时编辑源代码:只需在Scripts面板中双击源代码,然后在console.log之前添加换行符。 Press Ctrl+Enter or Ctrl+S to commit your change into the virtual machine. 按Ctrl + Enter或Ctrl + S将更改提交到虚拟机。 Then set breakpoint on the new line containing console.log. 然后在包含console.log的新行上设置断点。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM