Created
October 4, 2011 06:26
-
-
Save pamelafox/1261016 to your computer and use it in GitHub Desktop.
Sending JS errors to server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does it work on WebKit browsers these days?