Skip to content

Instantly share code, notes, and snippets.

@mallond
Created June 26, 2017 18:18
Show Gist options
  • Save mallond/b41cee66726fb96872446e1d52ed1fd4 to your computer and use it in GitHub Desktop.
Save mallond/b41cee66726fb96872446e1d52ed1fd4 to your computer and use it in GitHub Desktop.
Client Site JS Global Error Handler
<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {
// Note that col & error are new to the HTML 5 spec and may not be
// supported in every browser. It worked for me in Chrome.
var extra = !col ? '' : '\ncolumn: ' + col;
extra += !error ? '' : '\nerror: ' + error;
// You can view the information in an alert to see things working like this:
alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
// TODO: Report this error via ajax so you can keep track
// of what pages have JS issues
var suppressErrorAlert = true;
// If you return true, then error alerts (like in older versions of
// Internet Explorer) will be suppressed.
return suppressErrorAlert;
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment