Como se explica en este artículo de MDN, puede detectar errores de tiempo de ejecución de Javascript en un controlador de eventos window.onerror
MDN
CODIGO:
export class ErrorLogService {
private errors = new Array<any>();
constructor() {
let that = this;
window.onerror = function (msg, url, lineNo, columnNo, error) {
let string = msg.toLowerCase();
let substring = "script error";
if (string.indexOf(substring) > -1) {
console.log("Script Error: See Browser Console for Detail");
} else {
that.errors.push({
message: msg,
url: url,
line: lineNo,
column: columnNo,
error: error
});
}
return false;
};
window.document.addEventListener("error", (event: ErrorEvent) => {
if (event.target && (event.target as any).src) {
let url = (event.target as any).src;
this.errors.push({
message: "Resource not found",
url: url
});
} else {
this.errors.push({
message: "Unknown error",
error: event
});
}
}, true);
}
}
ESPERO TE AYUDE !!