windowonerror
Window.onerror is a global error handler provided by web browsers. It allows a web page to respond to uncaught JavaScript errors by assigning a function to window.onerror. This mechanism is long-standing and widely supported, though modern monitoring often uses additional techniques.
The handler is invoked when an unhandled exception occurs and is passed five arguments: message, source, lineno,
Common usage is to log errors to a server, report telemetry, or present a graceful message to
window.onerror = function (message, source, lineno, colno, error) {
fetch('/log', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message, source, lineno, colno, stack: error && error.stack
};
Window.onerror is complemented by other events such as the error event (window.addEventListener('error', ...)) and the unhandledrejection event
Limitations include that not all errors are delivered in all browsers, and certain errors may be swallowed