
Sentry Browser Sdk
Wire Sentry’s browser SDK so uncaught errors and rejections surface in production without ad-hoc console hunting.
Install
npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-browser-sdkWhat is this skill?
- Documents four automatic capture layers via default integrations (globalHandlers, browserApiErrors, optional console)
- Lists what global handlers miss—try/catch, swallowed async chains, validation failures—and when to call captureException
- Pins minimum @sentry/browser ≥7.0.0 and offline transport at ≥7.48.0 with linkedErrorsIntegration browser support notes
- Maps each layer to a specific Sentry integration name for correct opt-in/opt-out configuration
Adoption & trust: 1.5k installs on skills.sh; 197 GitHub stars; 1/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Production error visibility is the canonical shelf once the app is live; the skill documents how monitoring hooks into the browser runtime. Monitoring subphase matches SDK auto-capture layers (onerror, unhandledrejection, patched timers) and manual captureException guidance.
Common Questions / FAQ
Is Sentry Browser Sdk safe to install?
skills.sh reports 1 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Sentry Browser Sdk
# Error Monitoring — Sentry Browser SDK > Minimum SDK: `@sentry/browser` ≥7.0.0 > `makeBrowserOfflineTransport` requires `@sentry/browser` ≥7.48.0 > `linkedErrorsIntegration` `cause` chain requires Error.cause support (Chrome 93+, Firefox 91+) --- ## How Automatic Capture Works The browser SDK hooks into the browser environment and captures errors from multiple layers automatically: | Layer | Mechanism | Integration | |-------|-----------|-------------| | Uncaught synchronous exceptions | `window.onerror` | `globalHandlersIntegration` (default on) | | Unhandled promise rejections | `window.onunhandledrejection` | `globalHandlersIntegration` (default on) | | Errors in `setTimeout` / `setInterval` / `requestAnimationFrame` / `addEventListener` | Patched browser APIs | `browserApiErrorsIntegration` (default on) | | Console errors (optional) | Patched `console.error` | `captureConsoleIntegration` (opt-in) | ### What Requires Manual Instrumentation The global handlers only catch errors that **escape** your code. These are silently swallowed without manual calls: - Errors caught by your own `try/catch` blocks - Business-logic failures (validation errors, unexpected states) - Async errors in `.then()` chains where `.catch()` is attached - User-visible conditions that aren't exceptions (use `captureMessage`) --- ## Core Capture APIs ### `Sentry.captureException(error, captureContext?)` Captures an exception and sends it to Sentry. Prefer `Error` objects — they include stack traces. ```javascript import * as Sentry from "@sentry/browser"; // Basic usage try { riskyOperation(); } catch (err) { Sentry.captureException(err); } // With inline capture context try { await chargeCard(order); } catch (err) { Sentry.captureException(err, { level: "fatal", tags: { module: "checkout", payment_provider: "stripe" }, extra: { orderId: order.id, amount: order.total }, user: { id: "u_123", email: "user@example.com" }, fingerprint: ["checkout-payment-fail"], contexts: { payment: { provider: "stripe", amount: 9999, currency: "usd" }, }, }); } // Non-Error values are accepted but may lack stack traces Sentry.captureException("Something went wrong as a string"); ``` **`CaptureContext` shape:** | Field | Type | Description | |-------|------|-------------| | `level` | `"fatal" \| "error" \| "warning" \| "log" \| "info" \| "debug"` | Severity override for this event | | `tags` | `Record<string, string>` | Indexed, filterable key-value pairs | | `extra` | `Record<string, unknown>` | Unindexed supplementary data | | `user` | `{ id?, email?, username?, ip_address? }` | User identity | | `contexts` | `Record<string, Record<string, unknown>>` | Named structured context blocks | | `fingerprint` | `string[]` | Custom issue grouping key | --- ### `Sentry.captureMessage(message, levelOrContext?)` Captures a plain-text message as a Sentry issue. ```javascript // With a severity level (shorthand second argument) Sentry.captureMessage("Something went wrong", "warning"); Sentry.captureMessage("Payment gateway timeout", "fatal"); // With full CaptureContext Sentry.captureMessage("User performed invalid action", { level: "warning", user: { id: "u_456" }, tags: { feature: "cart", action: "remove-item" }, extra: { itemId: "sku_789" }, }); ``` > Set `attachStacktrace: true` in `Sentry.init()` to automatically attach a stack trace to message events. --- ### `Sentry.captureEvent(event)` Sends a fully constructed Sentry event object. Use `captureException` or `captureMessage` in application code; use `captureEvent` for custom integrations or forwarding from legacy loggers. ```javascript Sentry.captureEvent({ message: "Legacy logger forwarded event", level: "warning", tags: { source: "legacy-logger", module: "billing" }, extra: { rawLog: "something went wrong at line 42" }, timestamp: Date.now() / 1000, // Unix timestamp in seconds fingerprint: ["legacy-billing-error"], }); ``` --- #