JavaScript:有没有办法让 Chrome 解决所有错误? [英] JavaScript: Is there a way to get Chrome to break on all errors?

查看:29
本文介绍了JavaScript:有没有办法让 Chrome 解决所有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Chrome 中寻找与 Firebug 的中断所有错误"功能等效的功能.在脚本选项卡中,Chrome 有一个暂停所有异常",但这与中断所有错误并不完全相同.

I am looking for an equivalent in Chrome to the "break on all errors" functionality of Firebug. In the Scripts tab, Chrome has a "pause on all exceptions", but this is not quite the same as breaking on all errors.

例如,当加载包含以下代码的页面时,我希望 Chrome 在 foo.bar = 42 行中断.相反,即使启用在所有异常时暂停",我也没有得到预期的结果.

For instance, when loading a page with the following code, I would like Chrome to break on the line foo.bar = 42. Instead, even when enabling the "Pause on all exceptions", I don't get the expected result.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <script type="text/javascript">

            function doError() {
                foo.bar = 42;
            }

            window.onload = function() {
                try {
                    doError();
                } catch (e) {
                    console.log("Error", e);
                }
            }
        </script>
    </head>
    <body>
    </body>
</html>

您可以尝试在此页面上粘贴上面的代码 或使用这个 jsFiddle.

You can try the code pasted above on this page or using this jsFiddle.

推荐答案

我回答的原始链接现在无效.较新的 URL 将是 https://developers.google.com/web/tools/chrome-devtools/javascript/add-breakpoints#exceptions 截至 2016 年 11 月 11 日.

The original link I answered with is now invalid.The newer URL would be https://developers.google.com/web/tools/chrome-devtools/javascript/add-breakpoints#exceptions as of 2016-11-11.

我意识到这个问题有答案,但不再准确.使用上面的链接^

I realize this question has an answer, but it's no longer accurate. Use the link above ^

(链接由上面编辑替换)-您现在可以将其设置为在所有异常或未处理的异常上中断.(请注意,您需要在来源标签中才能看到该按钮.)

(link replaced by edited above) - you can now set it to break on all exceptions or just unhandled ones. (Note that you need to be in the Sources tab to see the button.)

Chrome 现在还添加了一些其他非常有用的断点功能,例如中断 DOM 更改或网络事件.

Chrome's also added some other really useful breakpoint capabilities now, such as breaking on DOM changes or network events.

通常我不会重新回答问题,但我自己也有同样的问题,我发现这个现在是错误的答案,所以我想我会把这些信息放在这里供后来搜索的人使用.:)

Normally I wouldn't re-answer a question, but I had the same question myself, and I found this now-wrong answer, so I figured I'd put this information in here for people who came along later in searching. :)

这篇关于JavaScript:有没有办法让 Chrome 解决所有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆