Electron

Introduction

Before integrating a new BugSplat SDK with your application, make sure to review the Getting Started resources and complete the simple startup tasks listed below.

  • โ€‹Sign up for a BugSplat account

  • โ€‹Log in using your email address

  • Create a new database for your application

Need any further help? Check out the full BugSplat documentation here, or email the team at [email protected].

Overview

BugSplat supports the collection of both electron.crashReporter (native) and node.js crash reports. Native crashes are generated via Crashpad and BugSplat requires symbol files in order to calculate the call stack.

If your app is packaged with electron-builder or similar you will need to upload application-specific symbol files in order to see full native call stacks. All symbol files must be uploaded to BugSplat via symupload. More information about uploading symbol files to BugSplat can be found here.

BugSplat-node can also be used to collect uncaughtException and unhandledRejection events in your application's JavaScript code.

Native

Configure electron.crashReporter to upload crash reports to BugSplat using the following steps. Electron symbol files will be automatically downloaded by BugSplat. If you package your application with additional binaries you will need to upload the corresponding symbol files in order to correctly resolve call stacks. Please skip to step 3 if your app does not include additional binaries.

Step 1

Use the Breakpad symupload utility to upload symbol files to BugSplat. For additional information on how to upload symbols to BugSplat using symupload please check out our Breakpad documentation.

Step 2

Verify that your application-specific symbol files show up on the Symbols page. Be sure to upload symbols for each released version of your application. For best results, integrate symupload into your build or release process.

Step 3

Add a require or an import statement for electron and call electron.crashReporter.start as shown in the example below. Replace company name, product name, database name, application key, user email, and comment. Note this initialization code will need to be added to each process you wish to capture errors from:

const electron = require('electron')
electron.crashReporter.start({
companyName: '<<company name>>',
productName: '<<product name>>',
submitURL: 'https://<<database name>>.bugsplat.com/post/electron/crash.php',
compress: true,
ignoreSystemCrashHandler: true,
extra: {
'key': '<<application key>>',
'email': '<<user email>>',
'comments': '<<comment>>'
}
})

Step 4

Generate a crash in one of the Electron processes to test your BugSplat integration:

process.crash()

Step 5

Navigate to the Crashes page in BugSplat and you should see a new crash report for your application. Click the link in the Id column to see details about your crash on the Crash page:

Crash Reporter Crashes
Crash Reporter Crash

Processing as Windows Native

BugSplat can process Breakpad crashes reported from Windows operating systems with our Windows backend, rather than the Breakpad backend. The advantage to this approach is that BugSplat will be able to display function arguments and local variables for each resolved stack frame. Another advantage of this approach is that our backend will automatically resolve Windows OS symbols.

To configure your Breakpad crashes to be processed by our Windows backend, create unique AppName/AppVersion combinations for the Windows versions of your application and upload .pdb, .dll and .exe files (rather than .sym files). The presence of .pdb, .dll or .exe files in the symbol store is what triggers the use of the Windows backend. Uploading Windows symbols can be done via our manual symbol upload page or our automated tool SendPdbs.

Node.js Configuration

To configure reporting of JavaScript or TypeScript errors in your main and renderer processes please see our Node.js documentation to install and configure bugsplat-node.

Once you've installed bugsplat-node, create an error handler for uncaughtExceptions and unhandledPromise rejections. We recommend you quit your application in the event of an uncaughtException or unhandledPromiseRejection. You may also want to add code to display a message to your user here:

const javaScriptErrorHandler = async (error) => {
await bugsplat.post(error);
app.quit();
}

Add the error handler created above to uncaughtException and unhandledPromiseRejection events:

process.on('unhandledRejection', javaScriptErrorHandler)
process.on('uncaughtException', javaScriptErrorHandler)

Many Electron applications run multiple Node.js processes. For instance, the electron-quick-start application runs both a main and a renderer process. You will need to require bugsplat in each process you want to capture errors. To capture errors in the renderer process, add the following to renderer.js:

Sometimes it is desirable to reload or quit the application when an error occurs in the renderer process. The following is an example of how to invoke the main process from the renderer and quit your application in the case of an unhandled exception in the renderer:

โ€‹renderer.jsโ€‹

window.onerror = async (messageOrEvent, source, lineno, colno, error) => {
await bugsplat.post(error)
ipcRenderer.send('rendererCrash')
}

โ€‹main.jsโ€‹

const electron = require('electron')
const ipcMain = electron.ipcMain
ipcMain.on('rendererCrash', function () {
// Display an error and reload or quit the app here
})

Test BugSplat by throwing a new error in either the main or renderer process:

throw new Error("BugSplat!");

Navigate to the Crashes page in BugSplat and 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:

Node.js Crashes
Node.js Crash

Thatโ€™s it! Your Electron application is now configured to post crash reports to BugSplat.

Node.js API

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); // A description placeholder that can be overridden at crash time
bugsplat.setDefaultAdditionalFilePaths([paths]); // Paths to files to be sent to BugSplat at post time (limit 1MB)
bugsplat.postAndExit(error, options); // Wrapper for post that calls process.exit(1) after posting error to BugSplat
bugsplat.post(error, options); // Aysnc function that posts an arbitrary Error object to BugSplat
// If the values options.appKey, options.user, options.email, options.description, options.additionalFilePaths 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)

Source Maps

BugSplat has the ability to map uglified and minified JavaScript function names, file names, and line numbers back to their original values via source maps. For information on how to configure your application to upload source maps to BugSplat, please see the link below.

Contributing

BugSplat loves open source software! If you have suggestions on how we can improve this integration, please reach out to [email protected], create an issue in our GitHub repo or send us a pull request.