Skip to content

Overview ​

Code that runs in a callback — a setTimeout handler, an animation frame, a click listener — runs outside any try/catch your app set up. When it throws, the error only reaches the global error handler, and for scripts served from another origin (a CDN) browsers reduce it to a bare Script error. with no message or stack.

browserApiErrorsIntegration wraps these callbacks at the source and keeps the original error, with its full stack, before the browser can strip it. The error is then re-thrown, so your app, DevTools and other handlers see exactly the same behavior as before.

It doesn't report anything by itself. The re-thrown error reaches GlobalErrorIntegration as usual; when the browser passed the error through intact, that's what gets reported, and only when it was reduced to Script error. does GlobalErrorIntegration report the original kept here instead. Every error is sent exactly once — no DedupeIntegration needed.

It wraps:

  • setTimeout and setInterval callbacks;
  • requestAnimationFrame callbacks;
  • addEventListener listeners on window, document and XMLHttpRequest (removeEventListener keeps working with the original function).

Usage ​

ts
import { use } from '@buglapse/browser'
import { browserApiErrorsIntegration } from '@buglapse/browser/integrations'

use(browserApiErrorsIntegration())

// or skip some of the wrappers:
use(browserApiErrorsIntegration({ requestAnimationFrame: false }))

Options ​

OptionTypeDefaultDescription
setTimeoutbooleantrueWrap setTimeout callbacks
setIntervalbooleantrueWrap setInterval callbacks
requestAnimationFramebooleantrueWrap requestAnimationFrame callbacks
eventTargetbooleantrueWrap event listeners on window, document and XMLHttpRequest

Since reporting happens in GlobalErrorIntegration, this integration has no effect if you turned that one off with disable('global-error').

If all your scripts are served from the page's own origin, or with crossorigin="anonymous" and an Access-Control-Allow-Origin header, browsers never strip the error and you don't need this integration.