Last active
May 4, 2016 13:30
-
-
Save brandonb927/b12b796dcbdec658708f to your computer and use it in GitHub Desktop.
Simple Client-side Error logging
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
<!-- | |
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