Ever wondered how to intercept javascript errors (that happen on client side browsers) for your live system? Yep, i know! Despite all the efforts, a visitor might encounter an issue in his "foobar" browser that you just couldn't test before you went live. So how to do it? This little guy is the savior:
window.onerror = function(errorMessage, url, line) {
}
I just stumbled upon
this blogpost by xing developer Christopher; who summarizes how they do it in xing. Pretty interesting and clever stuff, here is the code:
window.onerror = function(errorMessage, url, line) {
var loggerUrl = "https://www.xing.com/js/logger";
var parameters = "?description=" + escape(errorMessage)
+ "&url=" + escape(url)
+ "&line=" + escape(line)
+ "&parent_url=" + escape(document.location.href)
+ "&user_agent=" + escape(navigator.userAgent);
/** Send error to server */
new Image().src = loggerUrl + parameters;
};
For details read the original post
here.