如何故意冻结 chrome 中的 javascript(插件/控制台)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17497912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to deliberately freeze javascript in chrome (plugin/console)
提问by Zsolt Szilagyi
I want to inspect elements of my page in development that disappear right after he mouse leaves them. Fot this and other scenarios I want something like a "disable JS" plugin or console-command, that works not only at pageload time, but can completely halt any and every js of the current page at any time.
我想检查开发中的页面元素,这些元素在鼠标离开后立即消失。对于这个和其他场景,我想要一个类似“禁用 JS”插件或控制台命令的东西,它不仅可以在页面加载时工作,而且可以随时完全停止当前页面的任何和每个 js。
Does such a solution exist? I would prefer chrome, but accept firefox. Thanks.
是否存在这样的解决方案?我更喜欢 chrome,但接受 Firefox。谢谢。
采纳答案by Andrei Barsan
Try using the debugger;
directive (relevant MDN article). This acts like a breakpoint and should help you debug your scripts using the normal developer console.
尝试使用debugger;
指令(相关 MDN 文章)。这就像一个断点,应该可以帮助您使用普通的开发人员控制台调试脚本。
回答by Katie
What worked for me to pause execution:
暂停执行对我有用:
- Open Chrome javascript console (Ctrl+Shift+J)
- Go to "sources"
- On the right side, click the little "pause" icon, or press F8 to pause script execution.
- 打开 Chrome javascript 控制台 (Ctrl+Shift+J)
- 转到“来源”
- 在右侧,单击“暂停”小图标,或按 F8 暂停脚本执行。
You can also put in "breakpoints" within the same console. Try the following to use breakpoints:
您还可以在同一控制台中放入“断点”。尝试以下操作来使用断点:
- Open Chrome javascript console (Ctrl+Shift+J)
- Go to "sources"
- On the right side, click the little "pause" icon, or press F8 to pause script execution.
- Now you can click the "Step over", "Step Into", etc functions on the right side to slowly step into the code, line by line.
- You can also click on the line number for any of the sources to add a breakpoint. Breakpoints will stop the code execution when it is reached. You can enable/disable breakpoints on the right side next to the other buttons mentioned above.
- 打开 Chrome javascript 控制台 (Ctrl+Shift+J)
- 转到“来源”
- 在右侧,单击“暂停”小图标,或按 F8 暂停脚本执行。
- 现在您可以点击右侧的“Step over”、“Step Into”等功能,一行一行地慢慢步入代码。
- 您还可以单击任何源的行号以添加断点。断点将在到达时停止代码执行。您可以在上面提到的其他按钮旁边的右侧启用/禁用断点。