Javascript 如何在 Google Chrome 中调试无响应的页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10035840/
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 debug unresponsive page in Google Chrome?
提问by James Simpson
I've got a fairly complex javascript application (it uses no external frameworks) that users are currently testing (a couple thousand lines). I've been getting reports that users are getting the popup in Google Chrome saying:
我有一个相当复杂的 javascript 应用程序(它不使用外部框架),用户当前正在测试它(几千行)。我一直收到报告说用户在谷歌浏览器中看到弹出窗口说:
The following page(s) have become unresponsive. You can wait for them to become responsive or kill them.
以下页面没有响应。您可以等待它们做出响应或杀死它们。
They report that the only way to keep using the app is to open a new Chrome window, but that the messages comes back up every few minutes, and only happens when they try to go to a new page. They specifically said that they click to go to a new page, and the current page never changes, they just see the spinning loading icon for a minute until the popup comes sup.
他们报告说,继续使用该应用程序的唯一方法是打开一个新的 Chrome 窗口,但消息每隔几分钟就会返回,并且只有在他们尝试转到新页面时才会发生。他们特别说他们点击进入一个新页面,当前页面永远不会改变,他们只是看到旋转加载图标一分钟,直到弹出窗口出现。
The odd thing is that I've tested extensively on the exact version of Chrome (18) that these users are having issues with, and I've seen no problems. I'm sort of stumped and don't know where to look now since I've been unable to duplicate it, any ideas on where to look next to at least try and figure out what could even be causing that error?
奇怪的是,我已经对这些用户遇到问题的 Chrome (18) 的确切版本进行了广泛的测试,但我没有发现任何问题。我有点困惑,现在不知道该往哪里看,因为我一直无法复制它,关于在哪里查看的任何想法至少尝试找出可能导致该错误的原因?
回答by Jared
I know this is an old question but I had this problem as well, and my best recommendation to you is the following:
我知道这是一个老问题,但我也遇到了这个问题,我对您的最佳建议如下:
Close Chrome completely and then add " --enable-logging" to your chrome shortcut to start it with that flag, you can even add " --enable-logging --v=1" to enable verbose logging.
完全关闭 Chrome,然后将“--enable-logging”添加到您的 chrome 快捷方式以使用该标志启动它,您甚至可以添加“--enable-logging --v=1”以启用详细日志记录。
I know with me, inserting a breakpoint wasn't an option because it was in a new tab that crashed before I could even get the console up. However, by enabling logging, the console gets written to a file in your chrome data directory ("C:\Users\username\AppData\Local\Google\Chrome\User Data")
我知道,插入断点不是一个选项,因为它在一个新选项卡中,在我什至无法启动控制台之前就崩溃了。但是,通过启用日志记录,控制台会被写入 chrome 数据目录中的文件(“C:\Users\username\AppData\Local\Google\Chrome\User Data”)
I hope this helps somebody someday like it did me! :D
我希望这有助于有一天像对我一样的人!:D
回答by Colin Godsey
Use the chrome javascript debugger to pause (breaks running code) during the unresponsiveness. It takes some timing, but it should break in the middle of whatever is running too long. You can then use the debugger controls to step around and see what is looping unnecessarily.
在无响应期间使用 chrome javascript 调试器暂停(中断正在运行的代码)。这需要一些时间,但它应该在运行时间过长的中间中断。然后,您可以使用调试器控件来查看什么是不必要的循环。
回答by tgrrr
I had a page today that had some buggy JS (infinite loop) and I couldn't open the dev tools via keyboard shortcut or right click (Chrome 60.0.3112.113). Was able to get past this by:
我今天有一个页面有一些错误的 JS(无限循环),我无法通过键盘快捷键或右键单击(Chrome 60.0.3112.113)打开开发工具。能够通过以下方式解决这个问题:
- Open new tab
- Open dev tools (on empty tab)
- Enter URL and load
- Pause JS execution in dev tools
- 打开新标签
- 打开开发工具(在空选项卡上)
- 输入网址并加载
- 在开发工具中暂停 JS 执行
Maybe this will help someone! Also chrome debugger persists breakpoints across browser tabs (for same JS) so if I wasn't able to determine exactly what was causing the error, my breakpoints would still be there in a new tab!
也许这会帮助某人!此外,chrome 调试器会跨浏览器选项卡(对于相同的 JS)保留断点,因此如果我无法确定导致错误的确切原因,我的断点仍将存在于新选项卡中!