I came up with this script that will catch errors in the console of a website. You can also call the error report function with try/catch in any function.
window.onerror = function (msg, url, lineNo, columnNo, error) {
error_report(error);
return false;
}
function error_report(error) {
//Call AJAX function
if (window.XMLHttpRequest) {var xmlhttp = new XMLHttpRequest();}
else {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {}};
var uid=localStorage.getItem("KDI19842011QrwtA");
if (uid == null) {uid='blank';}
var url=window.location.href;
xmlhttp.open("GET","https://"+location.host+"/ajax/error-report.php?id="+url+"&uid="+uid+"&err="+error,true);
xmlhttp.send();
}
The code will record the page, error message, and user id if the user is signed in. This can be useful if you have users so you can respond to direct messages on bug reports…