Skip to content

Instantly share code, notes, and snippets.

@dtulig
Created October 12, 2010 02:48
Show Gist options
  • Save dtulig/621590 to your computer and use it in GitHub Desktop.
Save dtulig/621590 to your computer and use it in GitHub Desktop.
(function() {
function getRequest() {
var a = null;
if (window.XMLHttpRequest) {
try {
a = new XMLHttpRequest;
}
catch(c) {
}
} else if (window.ActiveXObject) {
for (var d = 0, b; b = ["MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"][d++];) {
try {
a = new ActiveXObject(b);
break;
} catch(c) {}
}
}
return a;
}
function log(obj) {
var params,
request = getRequest();
for (var i in obj) {
params += '&';
params += i + '=' + encodeURI(obj[i]);
}
request.open("POST", "/rpc/client-error-log");
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.send(params);
}
function errorHandler(message, url, line) {
if (url) {
var obj = {
'message': message,
'url': url,
'line': line
};
obj['href'] = (window.location ? window.location.href: '?');
log(obj);
}
return true;
}
window.onerror = errorHandler;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment