在Chrome / Firefox开发者工具中,是否可以隐藏除前两个错误以外的所有错误? (由于React提供了很多垃圾错误) [英] In Chrome/Firefox Developer Tools, is it Possible to Hide All But the First Two Errors? (Since React Gives LOTS of Garbage Errors)

查看:97
本文介绍了在Chrome / Firefox开发者工具中,是否可以隐藏除前两个错误以外的所有错误? (由于React提供了很多垃圾错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在React中,当出现问题时,您通常会在控制台中看到很多错误消息。有些可能是原始错误的重复,有些是与错误无关的错误,这些错误是由原始错误创建无效条件引起的。


在普通的JS应用中,这种情况只会发生因为第一个错误通常会中止代码执行,所以频率降低。但是在React中,它的呈现策略通常会在现有错误之后导致新错误(并且往往很冗长)。


因此,您经常会有一堵文字墙可以向上滚动浏览在每次刷新时,您实际上只需要: A)原始错误和/或 B)消息,React紧随其后抛出(即该错误


我的问题是:


是否可以配置任何浏览器的开发工具来折叠或隐藏前两个错误消息(由于重新加载)?


我可以使用配置选项,扩展名还是调用控制台功能的全局错误处理程序吗?不知道,还是某事 ...自动完成,所以我只能在重新加载时看到前两个?

解决方案

至少对于Chrome 86.0.4240.75或更早版本,开发人员工具只能显示前n个错误/警告


如果您想创建自己的插件,可以肯定地做到这一点!但是您可以尝试多种方法来避免从控制台中过滤掉不必要的日志。


例如,您可以确定要查看的消息级别:


或通过文本或正则表达式从过滤器$ b中过滤消息$ b


或过滤来自特定文件的消息:


In React when things go wrong you often wind up with A LOT of error messages in your console. Some can be duplicates of the original error, and some are unrelated errors caused by the original error creating invalid conditions.

In a normal JS app this happens, just less often, because the first error generally halts code execution. But in React, its rendering strategy often results in new errors after existing ones (and often they're quite verbose).

Thus, you often have a wall of text to scroll back up through on every refresh, when you actually need just: A) the original error, and/or B) the message React throws right after (ie. where that error actually occurred).

My question is:

Is it possible to configure any browser's dev tools to collapse or hide error messages after the first two (since reloading)?

Can I use a configuration option, or an extension, or a global error handler that calls a console function I don't know of, or something ... to automatically make it so I only see the first two on reload?

解决方案

Only showing first n errors/warning is not possible from the developer tools at least for Chrome 86.0.4240.75 or earlier.

If you want to create your own plugin, you can for sure achieve this!, but there are multiple things you can try to keep unnecessary logs filtered from the console.

For example, you can decide what level og messages you want to see:

or filter messages by text or regex from filter box

or filter messages from a particular file:

Learn more about log filtering from official guide.

这篇关于在Chrome / Firefox开发者工具中,是否可以隐藏除前两个错误以外的所有错误? (由于React提供了很多垃圾错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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