SDK reference

API reference

The runtime surface of @bugjar/reporter — init, open, close. Every config option lives in Getting started.

The SDK exposes three methods. For the full list of config options accepted by init, see Getting started.

BugJar.init(config)

Initializes the SDK and mounts the trigger button (unless ui.showTrigger: false). Call from inside a bugjar:ready listener — that's the signal that window.BugJar is attached and ready to use. Safe to call exactly once per page; repeat calls are silently ignored (the SDK is silent on customer sites by design — no devtools warnings).

BugJar.init(config?: BugJarConfig): BugJarPublicApi;

config is optional. When the SDK is loaded from /sdk/{publicKey}.js (the supported install path) the server inlines window.__BUGJAR_CONFIG__ ahead of the bundle, and init() reads projectKey from there. You only need to pass config when you're overriding something (hooks, ui, userToken, etc.).

window.addEventListener('bugjar:ready', () => {
  const reporter = BugJar.init({ ui: { position: 'bottom-left' } });
  // reporter.open() / reporter.close() if you need them
});

The same handle is also exposed as the BugJar global (window.BugJar) for any code that doesn't capture the return value.

init() is cheap: it mounts a small React root for the consent panel, installs in-memory ring buffers for console + network, and resolves any capture-invitation token in the URL. It does not start recording — recording only begins when the user clicks the trigger or you call open().

bugjar:ready event

After the SDK module loads and attaches itself to window.BugJar, it dispatches a CustomEvent on window:

window.dispatchEvent(new CustomEvent('bugjar:ready', { detail: { BugJar } }));

Register the listener BEFORE the <script src=".../sdk/{key}.js"> tag in your HTML — synchronous inline scripts run during parse, before deferred module scripts execute, so the listener is always in place when the event fires. No race conditions.

<script>
  window.addEventListener('bugjar:ready', () => {
    BugJar.init({ /* ... */ });
  });
</script>
<script src="https://console.bugjar.app/sdk/proj_live_xxx.js" type="module" async></script>

BugJar.open()

Programmatically open the consent panel. Useful when you've set ui.showTrigger: false and are driving the SDK from your own UI element.

BugJar.open(): void;

No-op if a capture is already in progress.

BugJar.close()

Cancel an in-progress capture or close the consent panel without submitting. The buffer is discarded; nothing uploads.

BugJar.close(): void;

No-op if nothing is open.

Lifecycle hooks

The two callbacks are passed to init rather than wired through a separate emitter:

BugJar.init({
    projectKey: 'proj_live_...',
    onReportSubmitted: (reportId) => analytics.track('bug_reported', { reportId }),
    onError: (err) => Sentry.captureException(err),
});

onReportSubmitted fires after a successful upload + finalize. onError fires for any failure during capture, redaction, upload, or token resolution. See Getting started → Configuration for both.