---
title: "JavaScript error tracking in the browser — bugd.one"
description: "Capture uncaught errors and unhandled promise rejections in the browser: crash reporter via script tag (ESM/UMD), releases and source-map upload with curl."
url: https://bugd.one/guides/javascript-error-tracking?lang=en
language: en
updated: 2026-11-22
type: guide
author: Eduard Ditler
alternate_de: https://bugd.one/guides/javascript-error-tracking
alternate_en: https://bugd.one/guides/javascript-error-tracking?lang=en
---
Guide · Last updated: 2026-11-22

# JavaScript error tracking in the browser

Capture uncaught errors and unhandled promise rejections in the browser: crash reporter via script tag (ESM/UMD), releases and source-map upload with curl.

Language: [Deutsch](https://bugd.one/guides/javascript-error-tracking)

> **In short**
>
> - One script tag is enough: `import { initCrashReporter } from 'https://bugd.one/crash-reporter.js'` and `initCrashReporter({ projectKey, release })`. Without module support use `crash-reporter.umd.js` (global `BugdoneCrashReporter`).
> - It captures **uncaught errors** (`error` event) and **unhandled promise rejections** (`unhandledrejection`) — plus anything you report with `captureException`.
> - For readable stack traces, use the same `release` in the reporter and in the source-map upload (`POST /api/v1/sourcemaps`, **Pro/Team**).
> - Included: the last steps before the error (breadcrumbs, crash reporter 1.1 and later). Not included: session replay, performance tracing.

In the browser the worst errors happen where you never see them: on a user's device, in a browser you do not test. The bugd.one crash reporter hooks into the page's global error events, groups identical errors and shows them in the dashboard — in about 3 KB (gzip) with no dependencies.

## Prerequisites

- A bugd.one project and its **publishable key** (`bk_live_…`) under **Project → Settings**. It can safely live in the frontend.
- For source maps additionally the **server key** (`bk_server_…`) and the Pro or Team plan (€9.90 or €29.90 per month including VAT; the 7-day trial counts as Pro). The server key belongs in your CI only, never in the bundle.

![Project settings with API key and allowed domains](https://bugd.one/screenshots/docs-api-key.webp)
*Project → Settings: this is where you find the API key (bk_live_…) and set the allowed domains.*

## Step by step

### Step 1: Add the crash reporter

The quickest way is as an ES module straight from bugd.one — no installation:

```html
<script type="module">
  import { initCrashReporter } from 'https://bugd.one/crash-reporter.js'

  initCrashReporter({
    projectKey: 'bk_live_YOUR_PROJECT_KEY',
    release: '1.4.2',
  })
</script>
```

For older environments without module support there is the UMD build. It exposes all functions on the global object `BugdoneCrashReporter`:

```html
<script src="https://bugd.one/crash-reporter.umd.js"></script>
<script>
  BugdoneCrashReporter.initCrashReporter({
    projectKey: 'bk_live_YOUR_PROJECT_KEY',
    release: '1.4.2',
  })
</script>
```

Include the script as early as possible, ideally in the `<head>`, so errors during app startup are captured too. In bundler projects (Vite, webpack) install the package (`npm install @bugdone/crash-reporter`) and import `initCrashReporter` from `@bugdone/crash-reporter`.

### Step 2: Set a release

The `release` is a free-form string — a version number or Git hash. It appears on every crash, separates errors of different versions and is the key for source maps. In Vite, for example:

```ts
import { initCrashReporter } from './vendor/crash-reporter'

initCrashReporter({
  projectKey: import.meta.env.VITE_BUGDONE_KEY,
  release: import.meta.env.VITE_GIT_SHA ?? 'dev',
})
```

### Step 3: Context, users and filters

With `defaultContext`, `getUserId` and `beforeSend` you enrich or filter events:

```ts
initCrashReporter({
  projectKey: 'bk_live_YOUR_PROJECT_KEY',
  release: '1.4.2',
  defaultContext: { tier: 'pro' },
  getUserId: () => currentUser?.id,      // hashed with SHA-256 before it leaves the page
  sampleRate: 1,                          // 0.1 = send only 10% of events
  beforeSend: (event) => (event.message.includes('ResizeObserver loop') ? null : event),
})
```

`getUserId` fills the “affected users” figure. The raw ID is never sent, only a hash; bugd.one additionally keys it server-side with a per-project secret.

### Step 4: Handled errors and React error boundaries

Errors you handle in a `catch` you report yourself. In React an error boundary does the job:

```tsx
import { Component, type ErrorInfo, type ReactNode } from 'react'
import { captureException } from './vendor/crash-reporter'

export class CrashBoundary extends Component<{ children: ReactNode }, { hasError: boolean }> {
  state = { hasError: false }
  static getDerivedStateFromError() { return { hasError: true } }
  componentDidCatch(error: Error, info: ErrorInfo) {
    captureException(error, { componentStack: info.componentStack })
  }
  render() { return this.state.hasError ? <p>Something went wrong.</p> : this.props.children }
}

try {
  await checkout(cart)
} catch (err) {
  captureException(err, { feature: 'checkout', step: 'payment' })
}
```

Without a bundler call `BugdoneCrashReporter.captureException(err, { … })` or `captureMessage('…')` on the UMD global.

### Step 5: Upload source maps

Generate source maps in your build (Vite: `build: { sourcemap: true }`) and upload them in CI after the build. The map's file name must match the bundle, so `index-abc123.js.map` for `index-abc123.js`:

```bash
for f in dist/assets/*.js.map; do
  curl -fsS -X POST "https://bugd.one/api/v1/sourcemaps" \
    -H "Authorization: Bearer $BUGD_SERVER_KEY" \
    -F "release=1.4.2" -F "filename=$(basename "$f")" -F "file=@$f;type=application/json"
done
```

The `release` must match the value in `initCrashReporter` exactly. The upload needs the **server key** — the publishable key is rejected with `403 server_key_required`, and without an active plan you get `403 plan_required`. After an upload, bugd.one also re-symbolicates existing crashes of that release. Limits: 20 MB per file, 500 MB of source maps per project. Instead of `curl` you can use the bundled Node script `cli/bin/bugdone.mjs upload-sourcemaps --release=… --path=dist/` (copy it into your repo as source code; it is not on npm).

> **About source maps**
>
> Do not publish the `.map` files on your web server if your source code is not meant to be public. bugd.one only needs them in its private storage; after the upload you can delete them from the deploy folder.

### Step 6: Test and environments

Trigger an error in the browser console tab, for example `setTimeout(() => { throw new Error('Test crash') })`. After at most 5 seconds (the reporter batches up to 20 events) the crash appears in the dashboard under **Crashes**.

The reporter detects the environment itself: `localhost`, `127.0.0.1`, `*.local`, `*.test` and private IPs count as `development`, everything else as `production`. For staging, set it explicitly:

```ts
initCrashReporter({
  projectKey: 'bk_live_YOUR_PROJECT_KEY',
  environment: location.hostname.startsWith('staging.') ? 'staging' : undefined,
})
```

Non-production crashes appear in the dashboard with a DEV marker but trigger **no emails, webhooks or Slack/Discord/Teams messages**. The project's development mode silences everything when needed.

![Crash list filtered by the “Development” environment with DEV and Live + DEV markers](https://bugd.one/screenshots/docs-crash-env.webp)
*“Development” filter in the crash list: DEV = only seen in development so far, Live + DEV = seen in both.*

## What gets captured

| Field | Content |
| --- | --- |
| Message and type | error message (max. 2 KB) and error type, e.g. `TypeError` |
| Stack trace | up to 30 frames, max. 8 KB; readable with source maps |
| Page | origin and path — without query string and fragment |
| Browser | browser, major version and operating system only, e.g. `Chrome 121 (Android)` |
| Release, environment | from the configuration or detected automatically |
| User | optional: hashed ID from `getUserId` |
| Context | `defaultContext` and your context from `captureException` |

Before sending, the reporter removes email addresses, JWT-like strings and Bearer tokens as well as values of keys such as `token`, `password` or `secret`. Identical errors within 60 seconds are sent only once; when the user leaves the page it flushes the buffer using `fetch` with `keepalive`.

![Crash detail with origin (app, environment, version, device, page) and key figures](https://bugd.one/screenshots/docs-crash-origin.webp)
*Crash detail: origin at a glance, plus occurrences, affected users, first seen and release.*

## Limits and notes

> **What the crash reporter cannot do**
>
> - **No session replay, no performance tracing:** errors and the last steps before them (breadcrumbs) are captured.
> - **No automatic capture of `console.error`** or failed network requests in the crash reporter (the bug report widget attaches such data to user reports).
> - **Cross-origin scripts:** errors from scripts on other domains without a CORS opt-in reach the page only as “Script error.” — filter them with `beforeSend` if needed.
> - **No offline buffer:** events that cannot be sent are lost.
> - **Source maps only for JavaScript** (`.js`, `.mjs`, `.cjs`) and only on the Pro/Team plan.

Quota: Pro 10,000, Team 100,000 crash events per 30 days and project (the trial counts as Pro). Development events count too. For each crash fingerprint and IP, at most 10 events per hour are counted; further ones only raise the group's counter. When the quota is exhausted the API answers with `429 quota_exceeded`.

## Further reading

- [Crash reporting in the documentation](https://bugd.one/docs#crash-reporting): reading a crash, environments, source maps
- [Add a bug report button to your website](https://bugd.one/guides/bug-report-button-website?lang=en): users report problems themselves, with a screenshot
- [bugd.one vs. Sentry](https://bugd.one/guides/sentry-alternative?lang=en): when Sentry is the better choice
- [OpenAPI specification](https://bugd.one/openapi.json) and [API reference](https://bugd.one/api-reference.md)

## Frequently asked questions

**Do I need an npm package for the crash reporter?**
No. You can install it from npm (`@bugdone/crash-reporter`) or load it with a script tag from `https://bugd.one/crash-reporter.js` (ES module) or `https://bugd.one/crash-reporter.umd.js` (global `BugdoneCrashReporter`). In bundler projects the npm package is the easiest way.

**How readable do minified stack traces become?**
With Pro or Team you upload your build's source maps using the server key. If the `release` in the reporter matches the one used for the upload, bugd.one shows the original file and line. Without uploaded source maps stack traces stay minified.

**Are errors from development and staging sent too?**
Yes, in the browser `enabledInDev` defaults to `true`. On `localhost`, private IPs and `*.local`/`*.test` the reporter sets the environment `development`: the crash appears in the dashboard with a DEV marker but triggers no emails or webhooks. It does count toward the quota though — with `enabledInDev: false` you do not send it at all.

**What about personal data in error messages?**
Before sending, the reporter strips URL query strings, email addresses, JWT/Bearer tokens and values of keys such as `token`, `password` or `secret`. User IDs from `getUserId` are hashed with SHA-256. Build further filters with `beforeSend`.

**Does the reporter also capture `console.error` or network errors?**
No. It captures `window.onerror` (uncaught errors) and `unhandledrejection`, plus anything you report yourself with `captureException` or `captureMessage`. The bug report widget, on the other hand, attaches the latest console errors to a user report.

## Related guides

- [Add a bug report button to your website](https://bugd.one/guides/bug-report-button-website?lang=en) — Embed a feedback widget with screenshots, annotation and “My reports” via one script tag — options, environments, privacy link and self-hosting via ZIP.
- [Set up React Native crash reporting](https://bugd.one/guides/react-native-crash-reporting?lang=en) — Capture unhandled JavaScript errors in React Native apps automatically: setup, environments via __DEV__, source maps and what is not captured.
- [bugd.one vs. Sentry: comparison](https://bugd.one/guides/sentry-alternative?lang=en) — An objective comparison of bugd.one and Sentry: pricing, EU data storage, features, platforms and self-hosting — with sources, as of October 2026.

## Up and running in two minutes

Create an account, add a project, paste your key — all Pro features free for 7 days, no credit card required.

[Try free for 7 days](https://bugd.one/login) · [Read the docs](https://bugd.one/docs) · [All guides](https://bugd.one/guides?lang=en)

---

bugd.one — https://bugd.one/guides/javascript-error-tracking?lang=en · Overview for AI agents: [llms.txt](https://bugd.one/llms.txt) · API: [openapi.json](https://bugd.one/openapi.json)
