I wrote a remote error logging function using window.onerror as suggested by @pimvdb
Err = {}; Err.Remoterr = {}; Err.Remoterr.onerror = function (msg, errorfileurl, lineno) { var jsonstring, response, pageurl, cookies; // Get some user input response = prompt("There has been an error. " + "It has been logged and will be investigated.", "Put in comments (and e-mail or phone number for" + " response.)"); // get some context of where and how the error occured // to make debugging easier pageurl = window.location.href; cookies = document.cookie; // Make the json message we are going to post // Could use JSON.stringify() here if you are sure that // JSON will have run when the error occurs // http://www.JSON.org/js.html jsonstring = "{\"set\": {\"jserr\": " + "{\"msg\": \"" + msg + "\", " + "\"errorfileurl\": \"" + errorfileurl + "\", " + "\"pageurl\": \"" + pageurl + "\", " + "\"cookies\": \"" + cookies + "\", " + "\"lineno\": \"" + lineno + "\", " + "\"response\": \"" + response + "\"}}}"; // Use the jquery cross-browser post // http://api.jquery.com/jQuery.post/ // this assumes that no errors happen before jquery has initialised $.post("?jserr", jsonstring, null, "json"); // I don't want the page to 'pretend' to work // so I am going to return 'false' here // Returning 'true' will clear the error in the browser return false; }; window.onerror = Err.Remoterr.onerror;
I use this between the head and body tags of a web page.
You want to change the JSON and URL that you publish, depending on how you are going to register the data server.
source share