Can I prevent the Chrome Developer Tools console from logging image 404 errors?

JavascriptImageGoogle Chrome-Devtools

Javascript Problem Overview


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

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?

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

Javascript Solutions


Solution 1 - Javascript

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

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).

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.

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.

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

-/404\s\(Not\sFound\)$/

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.

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

Solution 2 - Javascript

In the chrome developer tools, it's under the "Console" tab. Click "Filter" and it will be on the filter line as a checkbox.

Solution 3 - Javascript

As an alternative answer you could run a bit of javascript to alter the src attribute of the offending images when on your dev server (just make sure you don't publish it to your production environment!).

If you don't want to actually add javascript to the page (understandably) you could probably run the script on load of the page via a chrome plugin (perhaps the greasemonkey chrome clone - tampermonkey).

n.b. Thanks for the feedback, notably for this to work it'll need to be within an event after the dom is ready and before the images load.

Solution 4 - Javascript

In your app, in your 'catch' statement.. log the exception under 'console.warn' .. know it works with firebug. In Firebug, you can then find these 'errors' under the 'warnings' tab. I would like to think the same can be true for Chrome Developer Tools..

actually did something similar day ago.. my app would stop on some error, so, I instead used the 'try' and 'catch' block. My catch looks like: catch (e) { console.warn(e); }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPaul D. WaiteView Question on Stackoverflow
Solution 1 - JavascriptJeffery ToView Answer on Stackoverflow
Solution 2 - JavascriptPotassium IonView Answer on Stackoverflow
Solution 3 - JavascriptAlex KeySmithView Answer on Stackoverflow
Solution 4 - JavascriptAfroman MakgalemelaView Answer on Stackoverflow