/plushcap/analysis/sentry/sentry-client-javascript-reporting-window-onerror

Capture & Report JavaScript errors with window.onerror

What's this blog post about?

The window.onerror event is a special browser event that fires whenever an uncaught JavaScript error has been thrown. It's one of the easiest ways to log client-side errors and report them to your servers. By assigning a function to window.onerror, you can listen to this event and handle errors accordingly. The Error object and its stack property are particularly valuable for debugging purposes as they provide detailed information about the source location of each frame of the program when the error occurred. However, the implementation of the stack property differs among browsers, so tools like TraceKit, stacktrace.js, etc., can be used to normalize error strings across different browsers. The window.onerror event has been available in browsers for some time and is supported by most modern browsers. To capture as much error information as possible, you can also wrap functions in try/catch statements. Finally, the captured error data needs to be transmitted to your servers using a reporting web service that supports CORS if necessary.

Company
Sentry

Date published
Jan. 4, 2016

Author(s)
Ben Vinegar

Word count
1417

Hacker News points
None found.

Language
English


By Matt Makai. 2021-2024.