2015-08-27 15:11:51 +00:00
|
|
|
# crashReporter
|
2013-08-14 22:43:35 +00:00
|
|
|
|
2016-04-21 22:39:12 +00:00
|
|
|
> Submit crash reports to a remote server.
|
2015-08-25 12:01:57 +00:00
|
|
|
|
2016-11-23 19:20:56 +00:00
|
|
|
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
|
2016-11-03 17:26:00 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
The following is an example of setting up Electron to automatically submit
|
|
|
|
crash reports to a remote server:
|
2013-08-14 22:43:35 +00:00
|
|
|
|
|
|
|
```javascript
|
2018-09-13 16:10:51 +00:00
|
|
|
const { crashReporter } = require('electron')
|
2015-08-28 17:50:30 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' })
|
2013-08-14 22:43:35 +00:00
|
|
|
```
|
|
|
|
|
2016-03-17 13:29:32 +00:00
|
|
|
For setting up a server to accept and process crash reports, you can use
|
|
|
|
following projects:
|
|
|
|
|
|
|
|
* [socorro](https://github.com/mozilla/socorro)
|
2016-05-06 17:09:24 +00:00
|
|
|
* [mini-breakpad-server](https://github.com/electron/mini-breakpad-server)
|
2016-03-17 13:29:32 +00:00
|
|
|
|
2018-02-26 22:37:18 +00:00
|
|
|
Or use a 3rd party hosted solution:
|
|
|
|
|
2019-05-09 17:30:37 +00:00
|
|
|
* [Backtrace](https://backtrace.io/electron/)
|
2018-06-19 15:32:37 +00:00
|
|
|
* [Sentry](https://docs.sentry.io/clients/electron)
|
2019-05-07 02:37:24 +00:00
|
|
|
* [BugSplat](https://www.bugsplat.com/docs/platforms/electron)
|
2018-02-26 22:37:18 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
Crash reports are stored temporarily before being uploaded in a directory
|
|
|
|
underneath the app's user data directory (called 'Crashpad' on Windows and Mac,
|
|
|
|
or 'Crash Reports' on Linux). You can override this directory by calling
|
|
|
|
`app.setPath('crashDumps', '/path/to/crashes')` before starting the crash
|
|
|
|
reporter.
|
|
|
|
|
|
|
|
On Windows and macOS, Electron uses
|
|
|
|
[crashpad](https://chromium.googlesource.com/crashpad/crashpad/+/master/README.md)
|
|
|
|
to monitor and report crashes. On Linux, Electron uses
|
|
|
|
[breakpad](https://chromium.googlesource.com/breakpad/breakpad/+/master/). This
|
|
|
|
is an implementation detail driven by Chromium, and it may change in future. In
|
|
|
|
particular, crashpad is newer and will likely eventually replace breakpad on
|
|
|
|
all platforms.
|
2016-10-05 21:10:45 +00:00
|
|
|
|
2020-09-24 15:22:50 +00:00
|
|
|
### Note about Node child processes on Linux
|
|
|
|
|
|
|
|
If you are using the Node.js `child_process` module and want to report crashes
|
|
|
|
from those processes on Linux, there is an extra step you will need to take to
|
|
|
|
properly initialize the crash reporter in the child process. This is not
|
|
|
|
necessary on Mac or Windows, as those platforms use Crashpad, which
|
|
|
|
automatically monitors child processes.
|
|
|
|
|
|
|
|
Since `require('electron')` is not available in Node child processes, the
|
|
|
|
following APIs are available on the `process` object in Node child processes.
|
|
|
|
Note that, on Linux, each Node child process has its own separate instance of
|
|
|
|
the breakpad crash reporter. This is dissimilar to renderer child processes,
|
|
|
|
which have a "stub" breakpad reporter which returns information to the main
|
|
|
|
process for reporting.
|
|
|
|
|
|
|
|
#### `process.crashReporter.start(options)`
|
|
|
|
|
|
|
|
See [`crashReporter.start()`](#crashreporterstartoptions).
|
|
|
|
|
|
|
|
#### `process.crashReporter.getParameters()`
|
|
|
|
|
|
|
|
See [`crashReporter.getParameters()`](#crashreportergetparameters).
|
|
|
|
|
|
|
|
#### `process.crashReporter.addExtraParameter(key, value)`
|
|
|
|
|
|
|
|
See [`crashReporter.addExtraParameter(key, value)`](#crashreporteraddextraparameterkey-value).
|
|
|
|
|
|
|
|
#### `process.crashReporter.removeExtraParameter(key)`
|
|
|
|
|
|
|
|
See [`crashReporter.removeExtraParameter(key)`](#crashreporterremoveextraparameterkey).
|
|
|
|
|
2015-08-25 12:01:57 +00:00
|
|
|
## Methods
|
|
|
|
|
2016-11-21 23:42:24 +00:00
|
|
|
The `crashReporter` module has the following methods:
|
2015-08-25 12:01:57 +00:00
|
|
|
|
|
|
|
### `crashReporter.start(options)`
|
2013-11-13 11:12:13 +00:00
|
|
|
|
2016-02-16 04:11:05 +00:00
|
|
|
* `options` Object
|
|
|
|
* `submitURL` String - URL that crash reports will be sent to as POST.
|
2019-04-30 20:55:33 +00:00
|
|
|
* `productName` String (optional) - Defaults to `app.name`.
|
2020-05-07 20:31:26 +00:00
|
|
|
* `companyName` String (optional) _Deprecated_ - Deprecated alias for
|
|
|
|
`{ globalExtra: { _companyName: ... } }`.
|
|
|
|
* `uploadToServer` Boolean (optional) - Whether crash reports should be sent
|
|
|
|
to the server. If false, crash reports will be collected and stored in the
|
|
|
|
crashes directory, but not uploaded. Default is `true`.
|
|
|
|
* `ignoreSystemCrashHandler` Boolean (optional) - If true, crashes generated
|
|
|
|
in the main process will not be forwarded to the system crash handler.
|
|
|
|
Default is `false`.
|
2020-04-14 17:36:31 +00:00
|
|
|
* `rateLimit` Boolean (optional) _macOS_ _Windows_ - If true, limit the
|
|
|
|
number of crashes uploaded to 1/hour. Default is `false`.
|
2020-05-18 15:09:50 +00:00
|
|
|
* `compress` Boolean (optional) - If true, crash reports will be compressed
|
2020-09-03 19:43:58 +00:00
|
|
|
and uploaded with `Content-Encoding: gzip`. Default is `true`.
|
2020-05-07 20:31:26 +00:00
|
|
|
* `extra` Record<String, String> (optional) - Extra string key/value
|
|
|
|
annotations that will be sent along with crash reports that are generated
|
|
|
|
in the main process. Only string values are supported. Crashes generated in
|
|
|
|
child processes will not contain these extra
|
|
|
|
parameters to crash reports generated from child processes, call
|
|
|
|
[`addExtraParameter`](#crashreporteraddextraparameterkey-value) from the
|
|
|
|
child process.
|
|
|
|
* `globalExtra` Record<String, String> (optional) - Extra string key/value
|
|
|
|
annotations that will be sent along with any crash reports generated in any
|
|
|
|
process. These annotations cannot be changed once the crash reporter has
|
|
|
|
been started. If a key is present in both the global extra parameters and
|
|
|
|
the process-specific extra parameters, then the global one will take
|
|
|
|
precedence. By default, `productName` and the app version are included, as
|
|
|
|
well as the Electron version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
**Note:** You can test out the crash reporter by generating a crash using
|
|
|
|
`process.crash()`.
|
|
|
|
|
|
|
|
**Note:** If you need to send additional/updated `extra` parameters after your
|
|
|
|
first call `start` you can call `addExtraParameter`.
|
|
|
|
|
|
|
|
**Note:** 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 127 bytes.
|
|
|
|
Keys with names longer than the maximum will be silently ignored. Key values
|
|
|
|
longer than the maximum length will be truncated.
|
|
|
|
|
|
|
|
**Note:** Calling this method from the renderer process is deprecated.
|
2015-05-30 02:03:59 +00:00
|
|
|
|
2015-08-25 12:01:57 +00:00
|
|
|
### `crashReporter.getLastCrashReport()`
|
2014-11-11 12:20:36 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
Returns [`CrashReport`](structures/crash-report.md) - The date and ID of the
|
|
|
|
last crash report. Only crash reports that have been uploaded will be returned;
|
|
|
|
even if a crash report is present on disk it will not be returned until it is
|
|
|
|
uploaded. In the case that there are no uploaded reports, `null` is returned.
|
2016-09-24 23:59:30 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** Calling this method from the renderer process is deprecated.
|
2014-11-11 12:20:36 +00:00
|
|
|
|
2015-08-25 12:01:57 +00:00
|
|
|
### `crashReporter.getUploadedReports()`
|
2015-06-05 11:05:55 +00:00
|
|
|
|
2016-11-08 04:54:34 +00:00
|
|
|
Returns [`CrashReport[]`](structures/crash-report.md):
|
2016-09-24 23:59:30 +00:00
|
|
|
|
2015-08-26 23:28:44 +00:00
|
|
|
Returns all uploaded crash reports. Each report contains the date and uploaded
|
|
|
|
ID.
|
2015-06-05 11:05:55 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** Calling this method from the renderer process is deprecated.
|
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
### `crashReporter.getUploadToServer()`
|
2016-11-08 00:12:46 +00:00
|
|
|
|
2017-11-29 10:58:24 +00:00
|
|
|
Returns `Boolean` - Whether reports should be submitted to the server. Set through
|
2016-11-22 08:30:20 +00:00
|
|
|
the `start` method or `setUploadToServer`.
|
2016-11-08 00:12:46 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** Calling this method from the renderer process is deprecated.
|
2016-11-08 00:39:11 +00:00
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
### `crashReporter.setUploadToServer(uploadToServer)`
|
2016-11-08 00:03:57 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
* `uploadToServer` Boolean - Whether reports should be submitted to the server.
|
2016-11-08 00:03:57 +00:00
|
|
|
|
2016-11-28 23:03:10 +00:00
|
|
|
This would normally be controlled by user preferences. This has no effect if
|
|
|
|
called before `start` is called.
|
2016-11-08 00:03:57 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** Calling this method from the renderer process is deprecated.
|
2016-11-08 00:39:11 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
### `crashReporter.getCrashesDirectory()` _Deprecated_
|
2017-11-02 01:57:43 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
Returns `String` - The directory where crashes are temporarily stored before being uploaded.
|
2017-11-02 01:57:43 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** This method is deprecated, use `app.getPath('crashDumps')` instead.
|
2017-02-09 20:47:02 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
### `crashReporter.addExtraParameter(key, value)`
|
2017-11-02 01:21:41 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
* `key` String - Parameter key, must be no longer than 39 bytes.
|
|
|
|
* `value` String - Parameter value, must be no longer than 127 bytes.
|
2017-11-02 01:21:41 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
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.
|
2017-11-02 01:21:41 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
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.
|
2017-11-02 01:21:41 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
**Note:** Parameters have limits on the length of the keys and values. Key
|
2020-07-30 02:04:04 +00:00
|
|
|
names must be no longer than 39 bytes, and values must be no longer than 20320
|
2020-05-07 20:31:26 +00:00
|
|
|
bytes. Keys with names longer than the maximum will be silently ignored. Key
|
|
|
|
values longer than the maximum length will be truncated.
|
2017-11-02 01:21:41 +00:00
|
|
|
|
2020-07-30 02:04:04 +00:00
|
|
|
**Note:** On linux values that are longer than 127 bytes will be chunked into
|
|
|
|
multiple keys, each 127 bytes in length. E.g. `addExtraParameter('foo', 'a'.repeat(130))`
|
|
|
|
will result in two chunked keys `foo__1` and `foo__2`, the first will contain
|
|
|
|
the first 127 bytes and the second will contain the remaining 3 bytes. On
|
|
|
|
your crash reporting backend you should stitch together keys in this format.
|
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
### `crashReporter.removeExtraParameter(key)`
|
2019-10-14 21:38:54 +00:00
|
|
|
|
2020-05-07 20:31:26 +00:00
|
|
|
* `key` String - Parameter key, must be no longer than 39 bytes.
|
|
|
|
|
2020-08-18 07:55:16 +00:00
|
|
|
Remove an extra parameter from the current set of parameters. Future crashes
|
2020-05-07 20:31:26 +00:00
|
|
|
will not include this parameter.
|
|
|
|
|
|
|
|
### `crashReporter.getParameters()`
|
|
|
|
|
|
|
|
Returns `Record<String, String>` - The current 'extra' parameters of the crash reporter.
|
2019-10-14 21:38:54 +00:00
|
|
|
|
2016-11-21 23:42:24 +00:00
|
|
|
## Crash Report Payload
|
2014-05-22 12:20:17 +00:00
|
|
|
|
2016-04-22 13:53:26 +00:00
|
|
|
The crash reporter will send the following data to the `submitURL` as
|
|
|
|
a `multipart/form-data` `POST`:
|
2014-05-22 12:20:17 +00:00
|
|
|
|
2015-08-25 12:18:02 +00:00
|
|
|
* `ver` String - The version of Electron.
|
|
|
|
* `platform` String - e.g. 'win32'.
|
|
|
|
* `process_type` String - e.g. 'renderer'.
|
2017-11-29 10:38:35 +00:00
|
|
|
* `guid` String - e.g. '5e1286fc-da97-479e-918b-6bfb0c3d1c72'.
|
2015-08-25 12:18:02 +00:00
|
|
|
* `_version` String - The version in `package.json`.
|
2015-08-25 12:16:20 +00:00
|
|
|
* `_productName` String - The product name in the `crashReporter` `options`
|
2015-08-25 12:18:02 +00:00
|
|
|
object.
|
|
|
|
* `prod` String - Name of the underlying product. In this case Electron.
|
2015-08-25 12:16:20 +00:00
|
|
|
* `_companyName` String - The company name in the `crashReporter` `options`
|
2015-08-25 12:18:02 +00:00
|
|
|
object.
|
2016-03-17 13:29:32 +00:00
|
|
|
* `upload_file_minidump` File - The crash report in the format of `minidump`.
|
2016-10-10 14:31:05 +00:00
|
|
|
* All level one properties of the `extra` object in the `crashReporter`
|
|
|
|
`options` object.
|