SDK · JavaScript
JavaScript
Dependency-free SDK for the browser and Node.js (≥14). No build step. Transport is fetch() with keepalive — never sendBeacon, which cannot set the X-Bugwatch-Key header. Ships CJS + ESM entry points with TypeScript types.
Install
Shell
npm install bugwatch-sdk-js
Or copy bugwatch.js to your server and include it before your app code.
Browser (global)
HTML
<script src="/static/bugwatch.js"></script>
<script>
Bugwatch.init({
dsn: "https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1",
environment: "production",
release: "1.2.3",
sampleRate: 1.0
});
try {
throw new Error("Payment declined");
} catch (err) {
Bugwatch.captureException(err, {
tags: { module: "checkout" },
user: { id: "42", email: "user@example.com" }
});
}
Bugwatch.captureMessage("Cart confirmed", {
level: "info",
tags: { feature: "cart" }
});
Bugwatch.flush();
</script>Node.js (CommonJS)
JavaScript
const Bugwatch = require("bugwatch-sdk-js");
Bugwatch.init({
dsn: "https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1",
environment: "production"
});
process.on("uncaughtException", (err) => {
Bugwatch.captureException(err);
Bugwatch.flush();
});ESM / TypeScript
TypeScript
import Bugwatch from "bugwatch-sdk-js";
Bugwatch.init({
dsn: "https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1"
});
const eventId = Bugwatch.captureException(new Error("boom"));API
| API | Description |
|---|---|
| Bugwatch.init(options) | Configure the SDK. Returns true when the DSN was accepted. |
| captureException(error, {tags, user}) | Capture an exception (Error or string). Returns event_id or null. |
| captureMessage(message, {level, tags, user}) | Capture a message. Returns event_id or null. |
| setUser(user) | Set the current user. |
| setTag(key, value) | Add a current tag. |
| setContext(context) | Set context (optional request key). |
| flush(timeoutMs) | Wait for in-flight sends (default 5000 ms). |
init options: dsn, environment, release, sampleRate, debug, sendDefaultPii, allowHttp. Platform is reported as javascript; stacktraces are parsed from error.stack.
