Skip to content

Instantly share code, notes, and snippets.

@brandonb927
Last active May 4, 2016 13:30
Show Gist options
  • Save brandonb927/b12b796dcbdec658708f to your computer and use it in GitHub Desktop.
Save brandonb927/b12b796dcbdec658708f to your computer and use it in GitHub Desktop.
Simple Client-side Error logging
<!--
From: https://metric.io/blog/2014/04/simple-client-side-error-logging
Stacktrace.js available from http://stacktracejs.com
-->
<script src="/static/js/stacktrace.js"></script>
<script>
window.onerror = function() {
var stackTrace;
var argData;
var docData;
var request;
var _doc = {};
var errorLoggingUrl = "https://www.yoursite.com/error-logging-url";
_doc.URL = document.URL;
docData = encodeURIComponent(JSON.stringify(_doc));
argData = encodeURIComponent(JSON.stringify(arguments));
stackTrace = JSON.stringify(printStackTrace());
console.log(arguments);
request = new XMLHttpRequest();
request.open('POST', errorLoggingUrl);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onload = function (e) {};
request.send("docData=" + docData + "&" + "argData="+ argData + "&" + "stackTrace=" + stackTrace);
return false;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment