Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created October 4, 2011 06:26
Show Gist options
  • Save pamelafox/1261016 to your computer and use it in GitHub Desktop.
Save pamelafox/1261016 to your computer and use it in GitHub Desktop.
Sending JS errors to server
window.onerror = function(message, url, line_num) {
// Standard error information
var error = '\n JS Error: ' + message + ' from ' + url + ':' + line_num;
error += '\n URL: ' + document.URL;
// User agent info, using https://github.com/caseyohara/user-agent
var user_agent = new UserAgent();
error += '\n Browser: ' + user_agent.browser_name + ' ' + user_agent.browser_version + ' | OS: ' + user_agent.os + ' | Platform: ' + user_agent.platform;
// User information - I find it useful to know who's logged in, so I can contact them for more info. Modify for your own use.
if (USER_INFO) error += '\n User: ' + USER_INFO.email + ' http://' + window.location.host + '/user/' + USER_INFO.id;
// Send it using my standard AJAX wrapper function, POSTING to a view that calls logging.error() on the error= arg
sendData('log-error', 'error=' + error, function() {});
return false;
};
@PanosJee
Copy link

PanosJee commented Oct 4, 2011

Does it work on WebKit browsers these days?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment