Skip to main content

Browser

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

In the browser, @bugsee/bugsee captures global errors and unhandled rejections, console output, network requests, user interactions, the page URL and session replay. It keeps a rolling recording window and uploads it as a report when something goes wrong or when the user reports a bug.

If you use a UI framework, start from its page under Frameworks instead. They all build on what is described here.

Requirements​

  • A browser with ES2022 support.
  • An app token. Create a JavaScript application in Bugsee and choose Browser as its target; see Create your app.
  • For persistence across reloads, IndexedDB and Web Locks (navigator.locks). Web Locks needs a secure context (https:// or localhost). Without them the SDK keeps its data in memory.

Install​

npm install @bugsee/bugsee

You install only @bugsee/bugsee. It selects the browser build through package exports conditions. @bugsee/browser is an internal building block that you do not install.

Launch​

Call launch() as early as possible, at the top of your entry module.

main.ts
import { launch } from '@bugsee/bugsee';

launch('<your_app_token>', { appVersion: '1.4.2', appBuild: '381' });

In the browser launch() returns a Promise of the client. Await it if you need the client right away, and also if you need capture to be armed by a known point. The launch finishes an asynchronous step (it resolves the device id first) before it starts error and unhandled-rejection capture, so code that runs in the same synchronous task after an un-awaited launch() call runs before capture is armed, and an error thrown there is not reported. To avoid the gap, await launch(...) (or load your app after it settles) before running code you want covered:

const bugsee = await launch('<your_app_token>');

bugsee.addBreadcrumb({ message: 'checkout started' });

A second launch() in the same page is ignored with a warning and returns the existing client. A missing or empty token does not throw: the SDK reports one error through onError (or console.warn) and returns a disabled client.

App version and build​

Reports carry your app's version and build. Bugsee resolves them in this order:

  1. The appVersion and appBuild launch options.
  2. The build-time constants __BUGSEE_APP_VERSION__ and __BUGSEE_APP_BUILD__. The Vite and webpack plugins inject them when you give the plugin appVersion and appBuild, or set BUGSEE_APP_VERSION and BUGSEE_APP_BUILD in the build environment.
  3. Meta tags in the page:
<meta name="bugsee:app-version" content="2.4.1">
<meta name="bugsee:app-build" content="381">

A browser cannot read your package.json or environment at run time, so the version has to be baked in at build time. The Vite and webpack plugins do it for you. Without a plugin, define the two constants yourself. Angular's esbuild application builder takes a define map in angular.json (projects.<app>.architect.build.options.define):

"define": {
"__BUGSEE_APP_VERSION__": "\"2.4.1\"",
"__BUGSEE_APP_BUILD__": "\"381\""
}

Generate those two lines in CI from your own version and commit id. The same constants work with any bundler that can substitute globals: esbuild and Vite take define, webpack uses DefinePlugin, and Rollup has no define option, so use a replacement plugin such as @rollup/plugin-replace.

If no version is found, the SDK logs one warning and reports version 0.0.0 and build 0.

What is exported​

@bugsee/bugsee exports:

ExportDescription
launch(appToken, options?)Starts the SDK. In the browser it returns Promise<Bugsee>.
relaunch(options?)Restarts the SDK, optionally with new options.
getStatus()Returns the current BugseeStatus.
BugseeStatusThe status values getStatus() returns.
LifecycleEventsThe lifecycle event names. See Lifecycle.
addReportAttachment(input)Adds an attachment to reports.
getDefaultNetworkSanitizer()The default network redaction, to compose with your own filter.

The client has methods for user data, breadcrumbs, events and traces and manual reports.

Browser options​

launch(appToken, options) accepts the common options. These apply to the browser only:

OptionTypeDefaultDescription
replayboolean or objecttrueSession replay. false turns it off. See Session replay.
captureInteractionsbooleantrueRecord clicks, key presses and other interactions.
captureViewHierarchybooleantrueRecord the DOM view hierarchy.
captureUrlbooleantrueRecord the sanitized page URL as the url trace.
urlSanitizer(url: string) => string | nullnoneRuns after the default URL sanitizer. Return null to write nothing for that URL.
captureUserIdlebooleanfalseRecord user idle periods.
persistbooleanIndexedDB when availableKeep the capture window and the report queue in IndexedDB. false keeps everything in memory.
persistUserIdentifierbooleanfalseKeep the user identifier across page loads.
startInBlackoutbooleanfalseStart with capture paused. See Lifecycle.
maxDataSizenumber20 MB (30 MB with IndexedDB)Size cap of the recording, in megabytes.
diskProtectionbooleantrueStop writing when the origin's storage quota runs low.
captureDiskSpacebooleanfalseAdd low-disk telemetry to the capture system trace.

The report dialog has its own options: reportSummaryRequired, reportDescriptionRequired, reportEmailRequired, reportLabelsEnabled, reportLabelsRequired and reportPrioritySelectorEnabled, all false by default. Open the dialog with client.showReportDialog(); see Bug reporting.

Persistence​

By default the rolling capture window and the queue of reports waiting to upload live in IndexedDB. After a reload or browser restart the recent past is still there, and a report interrupted mid-upload is sent on the next visit.

The default applies only when the page exposes both IndexedDB and Web Locks. Otherwise the SDK stays in memory. Pass persist: true to store anyway, or persist: false to force memory. If the browser refuses to store data (over quota, some private modes), writes fail best effort and the error goes to onError.

When storage headroom drops below 50 MiB, the SDK stops writing replay, logs and network data to IndexedDB. Below 10 MiB it writes nothing. Set diskProtection: false to opt out.

Gotchas​

  • Content Security Policy. Allow connect-src https://api.bugsee.com (or your own endpoint) so uploads can leave the page.
  • Session replay records the DOM. Text and inputs are masked by default. Review Privacy before you ship.
  • Separate contexts. A worker is a separate JavaScript context with its own launch; use Web and Service Workers for workers.
  • Single page apps. Route names make reports easier to read. The framework adapters set them for you; without one, call client.setRoute('/orders/:id') with the route pattern, not the concrete URL.

Source maps​

Minified stack traces need source maps. See Symbolication.

Verify​

  1. Start your app with the launch call in place.
  2. Report a test error from your code:
const bugsee = await launch('<your_app_token>');
bugsee.logException(new Error('Bugsee test error'));
  1. Open the Bugsee dashboard. The report appears within a minute, with the console, network and replay data.

If nothing arrives, pass an onError callback to launch and check the browser's network panel for blocked requests to api.bugsee.com.

Found an issue, typo, or wrong statement on this page? Report it now →