Suppress Chrome 'Failed to load resource' messages in console

后端 未结 3 1850
一个人的身影
一个人的身影 2020-11-22 04:23

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 abso

3条回答
  •  渐次进展
    2020-11-22 04:59

    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.

提交回复
热议问题