Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress Chrome 'Failed to load resource' messages in console

I'm writing a script that uses an XMLHttpRequest to search for a file defined by a relative path, by attempting to resolve that relative path against other same domain absolute paths that the script is aware of, then attempting to load the file from that resolved url. If I encounter a 404, I just try to resolve the files relative path against another absolute path, and try again. For this particular script, its perfectly fine to encounter a 404- however, my console is littered with 'Failed to load resource: the server responded with a status of 404 (Not Found) messages, and I want to suppress them.

There is no error to catch as far as I can see- error cases are handled by the xmlHttpRequest.onreadystatechange handler, and there is no window.onerror.

Is there any way to suppress these messages?

Thanks

like image 766
VLostBoy Avatar asked Dec 21 '10 15:12

VLostBoy


People also ask

How do I fix failed to load resources?

Chrome's cache clearing process, check all the options, and set the time range to “All time.” After you've cleared your cache, this might reset any options that were producing the error. Check the page in question to see if the resource is now displaying correctly. If not, you can also try resetting Chrome flags.

How do I enable the JavaScript console in Chrome?

Press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, ChromeOS) to open the Console, right here on this very page.


2 Answers

This feature was introduced last year. You can enable it here: DevTools->Settings->General->Console->Hide network messages.

Hiding network messages in Chrome DevTools

See also Filtering the Console output and Additional settings in the devtools documentation.

like image 59
Konrad Dzwinel Avatar answered Sep 24 '22 19:09

Konrad Dzwinel


Use console.clear() in the catch block or error handler function. It will clear those request error on the console immediately after it is logged.

PLEASE NOTE

From MDN

Note that in Google Chrome, console.clear() has no effect if the user has selected "Preserve log upon navigation" in the settings.

Read more about it on MDN

try {    var req = new XMLHttpRequest();    req.open('GET', 'https://invalidurl', false);    req.send();  } catch(e) {    console.clear();  }

Should log this

GET https://invalidurl/ net::ERR_NAME_NOT_RESOLVED

but it will be cleared.

like image 32
Abk Avatar answered Sep 24 '22 19:09

Abk