catch-all-errors
Version:
Catch all JavaScript errors and post them to your server
58 lines (51 loc) • 1.52 kB
HTML
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<script src="index.js" data-post-url="example-api.php" data-callback="catcher" data-email-to='support@yoursite.net' data-continuous></script>
<style>
html, body {
margin: 0px;
padding: 0px;
font-family: Arial;
}
#content {
max-width: 600px;
margin: auto auto;
}
input {
width: 100%;
}
</style>
</head>
<body>
<script>
window.onload = function() {
var el = document.getElementById("testInput");
var barf = function() {
setTimeout(function() {
el.value = "";
}, 1);
throw new Error('borked with "' + el.value + '"');
};
if (el.addEventListener) {
el.addEventListener('change', barf, true);
} else {
el.attachEvent('onchange', barf);
}
// trigger an error at startup
blee();
}
function catcher(e) {
console.log("Processing a caught error:", e);
document.getElementById("log").innerHTML += "Caught: " + e.message + "\n";
}
</script>
<div id="content">
<p>To trigger an error, type something into the text field and hit [Enter].</p>
<p><input type="text" id="testInput" name="testInput" placeholder="Error message..."></p>
<pre id="log"></pre>
</div>
</body>
</html>