Skip to main content
@squasher-ai/browser is the browser-native SDK for Squasher. It captures frontend errors, Core Web Vitals, page context, analytics-style events, and optional session replay without pulling Node-only code into your bundle.

Installation

Setup

Initialize the SDK once when your app boots:
src/main.ts
Errors, Web Vitals, and session replay all start automatically — no extra configuration needed. To also send console.error(...) calls as error events, enable console error capture:

Use a standalone client

init() sets the optional page-wide client used by the package-level helpers. Use BrowserClient directly when a component, micro-frontend, or test must own its SDK lifecycle:
Methods on BrowserClient do not use the page-wide client. Package-level helpers such as captureError() and close() continue to use the client created by init(). Each standalone client installs the automatic capture and replay features in its configuration, so disable features that another client already owns.

Automatic Capture

Once initialized, the browser SDK captures:
  • uncaught errors from window.onerror
  • unhandled promise rejections
  • Core Web Vitals: LCP, CLS, INP, FCP, and TTFB
  • automatic breadcrumbs for navigation, clicks, and failed fetches
  • console warnings and errors as breadcrumbs
  • a session identifier to correlate frontend errors, vitals, and replay data
Set captureConsoleErrors: true when you want console.error(...) calls to create their own error events, even if no exception is thrown.

Manual Capture

Use the helpers when you want to record explicit product or agent telemetry from the browser:

Next.js Web Vitals

If you build on Next.js, drop <SquasherNextWebVitals /> into your root layout. It bridges Next’s useReportWebVitals hook into the same transport, so you get both Core Web Vitals (LCP, CLS, INP, FCP, TTFB) and Next’s framework metrics (Next.js-hydration, Next.js-route-change-to-render, Next.js-render) tagged with the current route — without changing your init() config.
app/layout.tsx
The component automatically suppresses the SDK’s native web-vitals collector on mount so Core metrics aren’t reported twice. Pass an explicit path prop if you want to override the route tag (defaults to usePathname()).
This component imports from next/web-vitals and next/navigation and is only valid inside a Next.js app. If you’re on a different framework, the auto-collector that runs from init() already captures Core Web Vitals — you don’t need this component.

React Error Boundary

If you use React, the package also exports a small error boundary from @squasher-ai/browser/react:
src/providers.tsx

Session Replay

Replay is on by default once you call init(). The recorder batches rrweb events and flushes them automatically in the background, with a final sendBeacon() flush during page hide. Password inputs are masked by default. If you also call identify(), Squasher attaches that browser identity to replay uploads so the dashboard can attribute recorded sessions back to the same user context as your frontend errors. Tune sampling, masking, or block selectors when you record real customer sessions:
Opt out entirely with replay: { enabled: false }.

Configuration

Notes

  • Use @squasher-ai/nextjs instead when you need framework-specific Next.js middleware and route wrappers.
  • The base browser SDK stays framework-agnostic and works in SPAs, MPAs, and custom frontend shells.
  • Review your privacy posture before enabling session replay or logging rich console payloads in production.

Agent handoff