BugSplat-js is a JavaScript error-reporting system for web applications. Before continuing with the tutorial, please make sure you have completed the following checklist:
Install bugsplat via npm. This package currently requires Node.js 18 or later.
npm i bugsplat --saveIf you need to use a version of Node.js older than 18, you can install bugsplat@7.1.4.
Depending on your project's module system, you can either import or require BugSplat:
import { BugSplat } from 'bugsplat';const { BugSplat } = require('bugsplat');Node.js programs import the same client from bugsplat/node, which adds file attachments read from disk and a helper that exits the process after the report is posted:
import { BugSplatNode } from 'bugsplat/node';
const bugsplat = new BugSplatNode(database, application, version);
bugsplat.setDefaultAdditionalFilePaths(['/var/log/my-app.log']);
process.on('uncaughtException', (error) => bugsplat.postAndExit(error));
process.on('unhandledRejection', (reason) => bugsplat.post(reason as Error));post() and postFeedback() accept additionalFilePaths alongside the usual options. Files are uploaded under their base name; missing files are skipped, as are files that would push the upload past 10 MB.
Create a new instance of the BugSplat class with the name of your BugSplat database, the name of your application and the version of your application:
const bugsplat = new BugSplat(database, application, version);Listen for window.onerror events and post them to BugSplat:
window.onerror = async (event, source, lineno, colno, error) => {
await bugsplat.post(error);
}Also listen for window.unhandledpromiserejection events and post them to BugSplat:
window.onunhandledrejection = async (rejection) => {
await bugsplat.post(rejection.reason)
}Throw an exception after the event handler has been added.
throw new Error('BugSplat!');You can use bugsplat-js to capture errors that originate inside of try-catch blocks:
try {
throw new Error('BugSplat');
} catch(error) {
await bugsplat.post(error);
}You can also use bugsplat-js to post errors from promise rejections:
Promise.reject(new Error('BugSplat!')).catch(error => bugsplat.post(error, {}));After posting an error with bugsplat-js, navigate to the Crashes page. You should see a new crash report for the application you just configured. Click the link in the ID column to see details about your crash on the Crash page:
Thatβs it! Your application is now configured to post crash reports to BugSplat.
Runnable samples live in examples/. Run each command from the example's own directory (for example cd examples/my-node-crasher). Every sample has a "Crash with cause" variant that throws an Error whose cause is a SyntaxError from JSON.parse, so you can see the chain in BugSplat as Caused by: rows.
- my-javascript-crasher β vanilla browser app importing
bugsplatfrom esm.sh.npm i && npm start, open http://localhost:8080 and click Error, Type Error, Unhandled Rejection or Crash with cause. - my-node-crasher β TypeScript Node.js app using
BugSplatNodefrombugsplat/node, run directly by Node 22.18+ with no build step.npm i && npm start, ornpm run start:with-cause;npm run nativeattaches a Node.js diagnostic report.
The Node example depends on bugsplat@^9.3.0, the first release with the bugsplat/node entry point.
In addition to the configuration demonstrated above, there are a few public methods that can be used to customize your BugSplat integration:
bugsplat.setDefaultAppKey(appKey); // Additional metadata that can be queried via BugSplat's web application
bugsplat.setDefaultUser(user); // The name or id of your user
bugsplat.setDefaultEmail(email); // The email of your user
bugsplat.setDefaultDescription(description); // Additional info about your crash that gets reset after every post
async bugsplat.post(error, options); // Posts an arbitrary Error object to BugSplat
// If the values options.appKey, options.user, options.email, options.description are set the corresponding default values will be overwritten
// Returns a promise that resolves with properties: error (if there was an error posting to BugSplat), response (the response from the BugSplat crash post API), and original (the error passed by bugsplat.post)When the error you post has a cause (or is an AggregateError with errors), bugsplat-js walks the chain automatically and posts it as the crash report: the posted error plus up to 100 linked entries, in discovery order (cause before errors[], depth-first), in at most 1 MB. Linked errors appear in BugSplat's callstack as Caused by: rows followed by their own stacks, with each error's own properties (for example a database driver's code or constraint) shown as locals. There's nothing to configure.
try {
await db.insert(users).values(user);
} catch (error) {
// The driver error on `error.cause` (SQLSTATE, constraint name, ...) is captured too
await bugsplat.post(error);
}If you need the chain for your own tooling, createExceptionChain(error) returns the same entries post() sends.
You can also submit non-crashing user feedback (e.g. bug reports, feature requests) using postFeedback. Feedback reports appear in BugSplat with the "User Feedback" crash type, grouped by title.
const response = await bugsplat.postFeedback('Login button does not respond', {
description: 'Tapping login on iPhone does nothing.',
user: 'jane@example.com',
email: 'jane@example.com',
});You can attach files such as screenshots:
const screenshot = document.querySelector('input[type="file"]').files[0];
await bugsplat.postFeedback('UI rendering issue', {
description: 'The sidebar overlaps the main content.',
attachments: [
{ filename: 'screenshot.png', data: screenshot },
],
});bugsplat-node is deprecated. Its BugSplatNode class ships in this package as bugsplat/node with the same API, so the upgrade is the import:
- import { BugSplatNode } from 'bugsplat-node';
+ import { BugSplatNode } from 'bugsplat/node';Remove bugsplat-node from your dependencies and require bugsplat 9.3.0 or newer. additionalFilePaths, setDefaultAdditionalFilePaths() and postAndExit() behave as before.
File attachments and exiting the process from an error handler moved out of the main entry so that it runs in browsers as well as Node.js. Import from bugsplat/node to get them back.
BugSplat loves open source software! Please check out our project on GitHub and send us a pull request.
If you have any additional questions, please email or support team, join us on Discord, or reach out via the chat in our web application.


