在 Chrome 中检测 JavaScript 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3595240/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:22:32  来源:igfitidea点击:

Detecting JavaScript errors in Chrome

javascriptgoogle-chrome

提问by ghenne

Chrome does not appear to give any indication that a page has JavaScript errors, unless you open up the JavaScript Console to check.

除非您打开 JavaScript 控制台进行检查,否则 Chrome 似乎没有任何迹象表明页面存在 JavaScript 错误。

Is there any way to have an indication that there were errors, and then automatically open the JavaScript Console? Can the JavaScript console be opened from JavaScript?

有什么办法可以提示有错误,然后自动打开JavaScript Console?JavaScript 控制台可以从 JavaScript 打开吗?

采纳答案by patrickmdnet

Chrome does not have a native ability to alert you to Javascript errors. However, this Chrome extension will show an alert icon in the address bar when a Javascript error occurs:

Chrome 没有本地功能来提醒您 Javascript 错误。但是,当发生 Javascript 错误时,此 Chrome 扩展程序将在地址栏中显示警报图标:

https://github.com/barbushin/javascript-errors-notifier

https://github.com/barbushin/javascript-errors-notifier

The extension can be installed here:

可以在此处安装扩展程序:

https://chrome.google.com/webstore/detail/jafmfknfnkoekkdocjiaipcnmkklaajd

https://chrome.google.com/webstore/detail/jafmfknfnkoekkdocjiaipcnmkklaajd

回答by rhino

I think you cannot open the console directly from your JavaScript code. And as far as I know, only Opera has the option to display the console automatically, right after any error occurs.

我认为您无法直接从 JavaScript 代码打开控制台。据我所知,只有 Opera 可以选择在发生任何错误后立即自动显示控制台。

回答by Eli Grey

No. Even calling console.logwill not display the console.

不。即使调用console.log也不会显示控制台。