admin管理员组文章数量:1182257
Say I have some JavaScript code like this:
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. 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.
Say I have some JavaScript code like this:
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. 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.
- If anyone's wondering why, I'm trying to debug a minified script hosted on a server not controlled by me. – icktoofay Commented Aug 6, 2011 at 7:23
- 2 Since Google Chrome 55 you can get multiple breakpoints per line. Please have a look here: - umaar.com/dev-tips/129-inline-breakpoints - youtube.com/watch?v=HF1luRD4Qmk&feature=youtu.be&t=573 – anddoutoi Commented Apr 4, 2017 at 8:28
- Use cautiously with large minified scripts as annotating the line with all of the breakpoint choices can take many minutes, effectively killing the thread. – ericP Commented Jan 18, 2020 at 6:34
3 Answers
Reset to default 21Here are 2 related solutions
1) De-obfuscate Source
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).
2) Pretty Print
(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 {}
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. Press Ctrl+Enter or Ctrl+S to commit your change into the virtual machine. Then set breakpoint on the new line containing console.log.
The comment by Nicolas Boisteault is the one to be used in latest versions of chrome.
In 2015 you can click the {} button called pretty print at the bottom left. – Nicolas Boisteault
本文标签: javascriptAdding a breakpoint in the middle of a line with Chrome Web InspectorStack Overflow
版权声明:本文标题:javascript - Adding a breakpoint in the middle of a line with Chrome Web Inspector - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738208639a2068729.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论