@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 Current Version: 10.42.0
@sentry/browser using your preferred package manager: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:- Install the Sentry Webpack plugin or Vite plugin
- Configure your build tool to generate source maps
- Upload source maps during your build process
Bundle Size
The browser SDK is optimized for tree-shaking. Only import what you need:Next Steps
- Configure Performance Monitoring
- Set up Session Replay
- Learn about Error Filtering
- Explore Custom Instrumentation