0

I know I can register a callback for JavaScript errors, like this:

window.onerror = function(message, url, line) {
    // ...
};

However, I'd also like to be notified of any other error that's being logged to the console, such as images that couldn't be loaded (HTTP status code 404) or any other HTTP request with a bad status code such as 500.

Is that possible, and if yes, how? Note that I only intend to use this for debugging purposes, so it doesn't matter if the solution only works in Chrome.

Marius Schulz
  • 15,976
  • 12
  • 63
  • 97
  • check this : http://stackoverflow.com/questions/5056737/getting-data-from-the-browsers-console-using-javascript?rq=1 – OneOfOne Sep 04 '13 at 12:04
  • Do you mean `console.log`? http://stackoverflow.com/questions/4539253/what-is-console-log – Joum Sep 04 '13 at 12:04

1 Answers1

0

It is perfectly possible to intercept the calls to console.log, thanks to javascript's flexibility :

var oldConsoleLog = console.log;

console.log = function (x) {
    oldConsoleLog.call(console, x);
    alert(' this message was printed into console ' + x) ;
}

Obviously, alerting would be very annoying, but you can change the alert to whatever callback or event raising of your like.

GameAlchemist
  • 18,995
  • 7
  • 36
  • 59