Skip to main content
The @sentry/browser package provides error tracking and performance monitoring for browser JavaScript applications.

Prerequisites

  • Node.js 18 or newer
  • A Sentry account and project DSN

Installation

1

Install the Package

Install @sentry/browser using your preferred package manager:
Current Version: 10.42.0
2

Initialize Sentry

Initialize Sentry as early as possible in your application. Call Sentry.init() before any other code runs:
The dsn (Data Source Name) tells the SDK where to send events. You can find your DSN in your Sentry project settings.
3

Verify Installation

Test that Sentry is working by triggering a test error:
You should see the error appear in your Sentry dashboard within a few seconds.

Usage

Capturing Errors

Capture exceptions manually:

Setting Context

Add context information to events:

Adding Breadcrumbs

Breadcrumbs help trace user actions leading to an error:

Performance Monitoring

Enable browser tracing for performance monitoring:

Session Replay

Capture session replays to see what users experienced:

Advanced Configuration

Environment Configuration

Filtering Events

Control which errors are sent to Sentry:

Custom Integrations

CDN Installation

You can also load Sentry directly from a CDN without npm/yarn:

Troubleshooting

Source Maps

For production builds, upload source maps to get readable stack traces:
  1. Install the Sentry Webpack plugin or Vite plugin
  2. Configure your build tool to generate source maps
  3. Upload source maps during your build process
Check out the Sentry Webpack Plugin or Sentry Vite Plugin for automated source map uploads.

Bundle Size

The browser SDK is optimized for tree-shaking. Only import what you need:
Be mindful of bundle size when adding integrations. Each integration adds to your bundle. Only enable integrations you actually use.

Next Steps