Child pages
  • [system-log] Record JavaScript errors in "System Log" [5.3.0-B1]
Skip to end of metadata
Go to start of metadata

One JavaScript error on a page can ruin all other (not related to the error) JavaScript on that page. I propose that we use "window.onerror" method for catching these errors (see http://stackoverflow.com/questions/951791/javascript-global-error-handling for more info) and through an AJAX call record them in "System Log".

This example code shows how to catch these errors:

$(window).on('error', function ($e) {
	var $original_event = $e.originalEvent;
	console.log($original_event);

	alert('col: ' + $original_event.colno + "\n" + 'line: ' + $original_event.lineno + "\n" + 'msg: ' + $original_event.message + "\n" + 'file: ' + $original_event.filename);
});

There is also not documented Error.prototype.stack property, which allows to retrieve stack track to the place, where error happened. The format of stack trace can vary greatly depending on used browser, but in general it can look like this:

Error: foobar
    at new bar (<anonymous>:241:11)
    at foo (<anonymous>:245:5)
    at callFunction (<anonymous>:229:33)
    at Object.InjectedScript._evaluateOn (<anonymous>:875:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:808:34)

Related Tasks