0

Just wondering if we can track any messages printed on dev tools console. Take an example, if any network request throws 404 for a resource file, chrome logs some 404 message on console. Can we track it? I tried overriding console but it did not work. Any thoughts on this?

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
Rohit
  • 11
  • 1
  • I don't think it uses the `window.console` object to log networks errors, and thus, I don't think there is a way to override it. – Kaiido Sep 15 '15 at 05:14

2 Answers2

0

Setting event listener for error event using capture event phase should help, as described in this question.

Community
  • 1
  • 1
Sergey Lapin
  • 2,633
  • 2
  • 18
  • 20
  • 1
    The linked answer (btw you should have flag the question as duplicate if you think it's one), only allows to capture the error events, fired by resources, not to get the error message displayed by the `console.error` method (all logged errors don't necessarily fire an error event). – Kaiido Sep 15 '15 at 10:00
0

Have a look at "https://github.com/ianpgall/js-console-listener, a "library that allows you to listen for console events".

Also http://www.paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ "Maintains a history of logs, so you can look in the past if your console is added afterwards"

HTH

jv-k
  • 618
  • 5
  • 20
  • The first link is just overriding the `window.console` object, which is what OP already tried, but won't work for i.e Network messages. The second link is just a custom logging method, which will route to the original `window.console.log` method, after it saved the log to a variable. You have to call it explicitly in your code, you won't get the log coming from other scripts and thus you won't get the Network logs either. – Kaiido Sep 16 '15 at 23:53