本文介绍了我可以阻止 Chrome 开发者工具控制台记录图像 404 错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次找不到页面资产(包括图像)(即返回 404)时,Chrome 开发者工具控制台都会记录一个错误.

The Chrome Developer Tools console logs an error each time a page asset (including an image) isn't found (i.e. returns 404).

在我的工作中,我经常在第三方提供图像并且在开发过程中可能无法使用的网站上工作.让每张丢失的图像在控制台中都显示为错误会使其他更重要的错误(例如 JavaScript 错误)更难以注意到.

In my work, I'm often working on sites where images are provided by third parties and may not be available during development. Having each missing image show up as an error in the console makes other more important errors (e.g. JavaScript errors) harder to notice.

是否有一个设置可以阻止控制台将未找到的图像记录为错误?

Is there a setting that stops the console logging unfound images as errors?

或者是否有某种方法可以通过与您可以在网络"选项卡中过滤请求的条件相同的类型来过滤控制台消息?

Or is there some way to filter console messages by the same sort of criteria that you can filter requests by in the Network tab?

(参见例如 http://chromium.googlecode.com/issues/attachment?aid=1337330000000&name=Screenshot-Google%2B+-+Google+Chrome.png&token=1F05er8uKjAQEEBrUITFjsIGJ2A%3A13588671a​​mp;in>)

(See e.g. http://chromium.googlecode.com/issues/attachment?aid=1337330000000&name=Screenshot-Google%2B+-+Google+Chrome.png&token=1F05er8uKjAQEEBrUITFjsIGJ2A%3A1358867878658&inline=1)

推荐答案

Chromium 团队已经开始"了这方面的工作:https://code.google.com/p/chromium/issues/detail?id=96212

Work has "started" on this by the Chromium team: https://code.google.com/p/chromium/issues/detail?id=96212

更新:该功能请求已于 2013 年 3 月 18 日关闭.我不确定此功能首次出现在哪个 Chrome 版本中,但我可以确认我的 Chrome v33 中的控制台过滤选项.0.1750.152 (Linux).

Update: The feature request was closed on March 18, 2013. I'm not sure in which version of Chrome this feature first appeared, but I can confirm console filtering options in my Chrome v33.0.1750.152 (Linux).

更新 2: 目前,当输入过滤器(纯文本或正则表达式)时,会根据消息文本(例如 GET http://example.com/foobar404(未找到))以及右侧链接的文本(例如 test.html:65).(我已向 Chromium 提交了一个问题来跟踪此问题.)

Update 2: Currently, when a filter (plain text or regular expression) is entered, it is tested against the message text (e.g. GET http://example.com/foobar 404 (Not Found)) as well as the text of the right side link (e.g. test.html:65). (I have filed an issue with Chromium to track this.)

作为一种解决方法,使用正则表达式过滤器,例如:

As a workaround, use a regular expression filter like:

^(?!.* 404 (Not Found))(?!.*[文件名])

其中 [file name] 是来自右侧链接的文件名.

where [file name] is the file name from the right side link.

例如,如果我的页面是 test.html,那么 ^(?!.* 404 (Not Found))(?!.*test.html) 会起作用.

For example, if my page is test.html, then ^(?!.* 404 (Not Found))(?!.*test.html) will work.

注意:这也将过滤掉消息文本中包含文件名的消息.我不确定现在有没有办法解决这个问题.

Note: This will also filter out messages that have the file name in the message text. I'm not sure there is a way around this for now.

更新(2019-06-05):这个表达式会过滤掉我当前版本的Chrome(75.0.3770.80)中的404:

Update (2019-06-05): This expression will filter out 404s in my current version of Chrome (75.0.3770.80):

-/404s(NotsFound)$/

在处理每个标记之前,过滤似乎首先用空格分割过滤器字符串,但它也会在正则表达式内部分割空格,因此 s 是必要的.

It seems the filtering first splits the filter string by whitespace before processing each token, but it will also split spaces inside of a regular expression, so the s's are necessary.

从技术上讲,这将过滤掉以(不区分大小写)字符串404(未找到)"结尾的任何消息,包括 console.log 消息.

Technically, this will filter out any message ending with the (case insensitive) string "404 (Not Found)", including console.log messages.

这篇关于我可以阻止 Chrome 开发者工具控制台记录图像 404 错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 14:48