Last updated 26 November 2026. By Paul Badarau.
Ines, a fictional developer, keeps a portfolio site with one contact form and no build step. She would rather paste ten lines of window.onerror than add a package, so she compares the two.
A window.onerror handler receives the message, the file, the line and column, and the error object for an uncaught error. It does not fire for a rejected promise, so a failed fetch in an async function needs a second listener on unhandledrejection. It records nothing that happened before the error, and it sends nowhere until you write the request.
@sentry/browser installs handlers for both of those events and adds, on every error:
- a parsed stack, which is what Monitoring groups issues by;
- breadcrumbs: the clicks, requests and console messages just before the error;
- the
releaseandenvironmentyou set, and debug IDs that match uploaded source maps; - the envelope format, the DSN key and the event ID Monitoring needs to accept an event;
- back-off: when Monitoring answers that a rate limit is reached, the SDK stops sending until it expires.
Choose the handler when you only want a line in your own server log and will read it yourself. Choose the SDK when you want grouped issues, an email the first time an error appears, and readable stacks from source maps.
One limit applies to both. When a script loads from another origin, such as a CDN, the browser hides its errors from the page and reports only Script error. with no file, line or stack. Neither a handler nor the SDK can read past that. Serve the script with a CORS header and add the crossorigin attribute to its script tag, and the details come through.
The product page for this is Monitoring.