diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 6907e1af..5a361d1a 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -85,6 +85,7 @@ export default class AnimeNotifier { document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this)) document.addEventListener("keydown", this.onKeyDown.bind(this), false) window.addEventListener("popstate", this.onPopState.bind(this)) + window.addEventListener("error", this.onError.bind(this)) // Idle requestIdleCallback(this.onIdle.bind(this)) @@ -1024,4 +1025,19 @@ export default class AnimeNotifier { return } } + + // This is called every time an uncaught JavaScript error is thrown + onError(evt: ErrorEvent) { + let report = { + message: evt.message, + stack: evt.error.stack, + fileName: evt.filename, + lineNumber: evt.lineno, + columnNumber: evt.colno, + } + + this.post("/api/new/clienterrorreport", report) + .then(() => console.log("Successfully reported the error to the website staff.")) + .catch(() => console.warn("Failed reporting the error to the website staff.")) + } } \ No newline at end of file