SDK reference
The full API surface of @trapify-tech/browser. If you just want to get started,
read the Quickstart instead. A machine-readable version of this
page lives at /llms.txt.
Entry points
@trapify-tech/browser— browser build. Usesfetch, hookswindow.onerror.-
@trapify-tech/browser/node— Node build. Uses thehttpsmodule, hooksprocess.uncaughtException. Fetch and navigation breadcrumbs do not apply and are skipped.
import {
init, captureException, captureMessage,
setUser, setTag, addBreadcrumb, close,
} from '@trapify-tech/browser'; init options
| Option | Type | Default | Description |
|---|---|---|---|
dsn | string | required | The 32-character hex key from project settings. |
environment | string | null | Attached to every event, e.g. production. |
release | string | null | Your app version, for release tracking. |
maxBreadcrumbs | number | 50 | How many breadcrumbs are kept in memory. |
autoCapture | boolean | true | Hook uncaught errors and unhandled rejections. |
captureConsole | boolean | true (browser) / false (Node) | Record console calls as breadcrumbs. Off by default in Node — server logs are noisy. |
captureFetch | boolean | true | Record fetch requests as breadcrumbs. Browser entry point only. |
debug | boolean | false | Log the SDK’s own failures to the console. |
beforeSend | function | — | Inspect, mutate or drop each event before it is sent. |
endpoint | string | production | Override the ingest URL. For testing. |
Functions
-
init(options)— Call once at startup, as early as possible so startup errors are captured. -
captureException(error, level?)— Send an Error manually. Fire-and-forget — it returns nothing. Level defaults to error. -
captureMessage(text, level?)— Send a message with no exception attached. Level defaults to info. -
setUser(user | null)— Attach id, email, username to all subsequent events. Pass null on logout. -
setTag(key, value)— Attach a searchable string tag to all subsequent events. -
addBreadcrumb(crumb)— Browser entry point only. Record a manual breadcrumb alongside the automatic ones. -
flush()— Node only. Await delivery of pending events before the process exits. -
close()— Unhook handlers and stop capturing. Used in tests and SSR teardown.
beforeSend — scrubbing data before it leaves
Trapify does no server-side scrubbing: what you send is what is stored (see Security & data handling). beforeSend is the place to strip anything you do not want to leave your
process. Return the event to send it, or null to drop it.
init({
dsn: process.env.TRAPIFY_DSN,
beforeSend(event) {
if (event.environment === 'development') return null; // drop entirely
delete event.user?.email; // or scrub and send
return event;
},
}); Node.js
import { init, withTrapify, errorHandler, flush } from '@trapify-tech/browser/node';
init({
dsn: process.env.TRAPIFY_DSN,
environment: 'production',
captureConsole: false, // default false in Node — server logs are noisy
}); withTrapify(handler) wraps an async handler — Cloud Functions, route handlers —
capturing unexpected errors and re-throwing them. Deliberate control-flow throws such as
Firebase HttpsError pass through uncaptured. errorHandler is the
Express-style middleware equivalent. In short-lived environments call flush() before
the process exits, or in-flight events are lost.
Multiple projects in one process
The module-level functions wrap a single default client. To send to more than one project,
construct clients directly with new TrapifyClient(options) — or
new TrapifyNodeClient(options) from the Node entry point — and call the same
methods on each instance. Pass autoCapture: false on all but one, or every
uncaught error is reported several times.