crashReporter
Submit crash reports to a remote server.
If you want to call this API from a renderer process with context isolation enabled,
place the API call in your preload script and
expose it using the
contextBridge API.
The following is an example of setting up Electron to automatically submit crash reports to a remote server:
const { crashReporter } = require('electron')
crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' })
For a guide to collecting, receiving and symbolicating crash reports, including how to run your own crash server or use a hosted service, see the Crash Reporting tutorial.
Electron uses Crashpad to monitor and report crashes. Crashpad uses the same upload protocol as Breakpad, so servers that accept Breakpad minidumps can receive Electron's crash reports.
Crash reports are stored under the directory returned by
app.getPath('crashDumps'). You can override it by calling
app.setPath('crashDumps', '/path/to/crashes') before starting the crash
reporter. The layout of files inside this directory is an implementation detail
and may change between versions of Electron.
The crashReporter module is disabled in Mac App Store builds. Its methods can
be called, but they do nothing: no crash reports are collected or uploaded,
getUploadedReports() returns an empty array and
getUploadToServer() returns
false.
Methods
The crashReporter module has the following methods:
crashReporter.start(options)
History
| Version(s) | Changes |
|---|---|
None | Added |
None | Deprecated calling this method in the renderer process. |
None | Default value of |
None | The |
This method must be called before using any other crashReporter APIs. Once
initialized this way, the crashpad handler collects crashes from all
subsequently created processes. The crash reporter cannot be disabled once
started.
This method should be called as early as possible in app startup, preferably
before app.on('ready'). If the crash reporter is not initialized at the time
a renderer process is created, then that renderer process will not be monitored
by the crash reporter.
You can test out the crash reporter by generating a crash using
process.crash().
If you need to send additional/updated extra parameters after your
first call start you can call addExtraParameter.
Parameters passed in extra, globalExtra or set with
addExtraParameter have limits on the length of the keys and values. Key
names must be at most 39 bytes long, and values must be no longer than 20320
bytes. Keys with names longer than the maximum are ignored, and a warning is
emitted. Values longer than the maximum length are truncated.
This method is only available in the main process.
crashReporter.getLastCrashReport()
History
| Version(s) | Changes |
|---|---|
None | Deprecated calling this method in the renderer process. |
Returns CrashReport | null - The date and ID of the
crash report with the most recent upload time, from the list returned by
getUploadedReports(). If there are no crash
reports at all, null is returned.
If no report has been uploaded yet but some are stored on disk, a report that has
not been uploaded may be returned. Check that its id is not empty before
treating it as uploaded.
This method is only available in the main process.
crashReporter.getUploadedReports()
History
| Version(s) | Changes |
|---|---|
None | Deprecated calling this method in the renderer process. |
Returns CrashReport[]:
Returns the crash reports stored on disk. Each report contains the date it was uploaded and the ID that the crash server returned for it.
Despite the method's name, reports that have not been uploaded (for example
because uploadToServer is false, the upload failed, or the report was rate
limited) are included too. For those reports, id is an empty string and date
is not meaningful. To list only uploaded reports, filter out reports with an
empty id.
This method is only available in the main process.
crashReporter.getUploadToServer()
History
| Version(s) | Changes |
|---|---|
None | Deprecated calling this method in the renderer process. |
Returns boolean - Whether reports should be submitted to the server. Set through
the start method or setUploadToServer.
This method is only available in the main process.
crashReporter.setUploadToServer(uploadToServer)
History
| Version(s) | Changes |
|---|---|
None | Deprecated calling this method in the renderer process. |
uploadToServerboolean - Whether reports should be submitted to the server.
This would normally be controlled by user preferences. This has no effect if
called before start is called.
This method is only available in the main process.
crashReporter.addExtraParameter(key, value)
keystring - Parameter key, must be no longer than 39 bytes.valuestring - Parameter value, must be no longer than 20320 bytes.
Set an extra parameter to be sent with the crash report. The values specified
here will be sent in addition to any values set via the extra option when
start was called. Calling this again with the same key replaces the value.
The value is read when a crash happens, so you can update it as your app's
state changes.
Parameters added in this fashion (or via the extra parameter to
crashReporter.start) are specific to the calling process. Adding extra
parameters in the main process will not cause those parameters to be sent along
with crashes from renderer or other child processes. Similarly, adding extra
parameters in a renderer process will not result in those parameters being sent
with crashes that occur in other renderer processes or in the main process.
Processes created with utilityProcess have no API for
setting extra parameters, so only globalExtra values are sent with their
crashes.
Parameters have limits on the length of the keys and values. Key names must be no longer than 39 bytes, and values must be no longer than 20320 bytes. Keys with names longer than the maximum are ignored, and a warning is emitted. Values longer than the maximum length are truncated.
crashReporter.removeExtraParameter(key)
keystring - Parameter key, must be no longer than 39 bytes.
Remove an extra parameter from the current set of parameters. Future crashes will not include this parameter.
crashReporter.getParameters()
Returns Record<string, string> - The current 'extra' parameters of the crash
reporter in the calling process, as set with the extra option and
addExtraParameter. Parameters set with the globalExtra option are not
included.
In Node child processes
Since require('electron') is not available in Node child processes (processes
run with ELECTRON_RUN_AS_NODE, such as those created with
child_process.fork()), the following APIs are available on the process
object in Node child processes.
If the crash reporter is started in the main process, Node child processes are monitored automatically. There is no way to start the crash reporter from a Node child process.
process.crashReporter.getParameters()
See crashReporter.getParameters().
process.crashReporter.addExtraParameter(key, value)
See crashReporter.addExtraParameter(key, value).
process.crashReporter.removeExtraParameter(key)
See crashReporter.removeExtraParameter(key).
Crash Report Payload
The crash reporter will send the following data to the submitURL as
a multipart/form-data POST. Unless compress is false, the request body
is gzip-compressed and sent with Content-Encoding: gzip.
verstring - The version of Electron.platformstring - e.g. 'win32'.process_typestring - e.g. 'renderer', or 'browser' for the main process.guidstring - e.g. '5e1286fc-da97-479e-918b-6bfb0c3d1c72'._versionstring - The version inpackage.json._productNamestring - The product name in thecrashReporteroptionsobject.prodstring - Name of the underlying product. In this case Electron._companyNamestring - The company name in thecrashReporteroptionsobject. Only sent if the deprecatedcompanyNameoption is set.upload_file_minidumpFile - The crash report in the format ofminidump.- All level one properties of the
globalExtraobject in thecrashReporteroptionsobject. - All extra parameters of the process that crashed, set with the
extraoption (main process only) oraddExtraParameter.
Crashpad and Chromium may add other fields to the upload. These are not part of Electron's API and can change without notice, so don't rely on them.
The body of the server's response is stored as the crash report's ID, and is
returned in the id field by
getUploadedReports().