2015-08-27 08:11:51 -07:00
# crashReporter
2013-08-14 15:43:35 -07:00
2016-04-21 15:39:12 -07:00
> Submit crash reports to a remote server.
2015-08-25 05:01:57 -07:00
2016-11-23 11:20:56 -08:00
Process: [Main ](../glossary.md#main-process ), [Renderer ](../glossary.md#renderer-process )
2016-11-03 10:26:00 -07:00
2015-08-25 05:16:20 -07:00
The following is an example of automatically submitting a crash report to a
remote server:
2013-08-14 15:43:35 -07:00
```javascript
2018-09-14 02:10:51 +10:00
const { crashReporter } = require('electron')
2015-08-28 10:50:30 -07:00
2013-11-14 13:39:44 +08:00
crashReporter.start({
productName: 'YourName',
companyName: 'YourCompany',
2015-11-13 16:03:40 +08:00
submitURL: 'https://your-domain.com/url-to-submit',
2017-01-10 16:07:10 -08:00
uploadToServer: true
2016-07-25 18:39:25 -07:00
})
2013-08-14 15:43:35 -07:00
```
2016-03-17 22:29:32 +09: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 10:09:24 -07:00
* [mini-breakpad-server ](https://github.com/electron/mini-breakpad-server )
2016-03-17 22:29:32 +09:00
2018-02-26 17:37:18 -05:00
Or use a 3rd party hosted solution:
2019-05-09 10:30:37 -07:00
* [Backtrace ](https://backtrace.io/electron/ )
2018-06-19 17:32:37 +02:00
* [Sentry ](https://docs.sentry.io/clients/electron )
2019-05-06 22:37:24 -04:00
* [BugSplat ](https://www.bugsplat.com/docs/platforms/electron )
2018-02-26 17:37:18 -05:00
2016-10-05 14:10:45 -07:00
Crash reports are saved locally in an application-specific temp directory folder.
For a `productName` of `YourName` , crash reports will be stored in a folder
named `YourName Crashes` inside the temp directory. You can customize this temp
directory location for your app by calling the `app.setPath('temp', '/my/custom/temp')`
API before starting the crash reporter.
2015-08-25 05:01:57 -07:00
## Methods
2016-11-21 15:42:24 -08:00
The `crashReporter` module has the following methods:
2015-08-25 05:01:57 -07:00
### `crashReporter.start(options)`
2013-11-13 19:12:13 +08:00
2016-02-16 12:11:05 +08:00
* `options` Object
2018-08-16 09:15:17 -07:00
* `companyName` String
2016-02-16 12:11:05 +08:00
* `submitURL` String - URL that crash reports will be sent to as POST.
2019-04-30 13:55:33 -07:00
* `productName` String (optional) - Defaults to `app.name` .
2019-05-28 10:17:01 -07:00
* `uploadToServer` Boolean (optional) - Whether crash reports should be sent to the server. Default is `true` .
2016-10-30 21:46:20 +11:00
* `ignoreSystemCrashHandler` Boolean (optional) - Default is `false` .
2019-08-05 10:45:58 -07:00
* `extra` Record< String , String > (optional) - An object you can define that will be sent along with the
2017-02-02 13:01:49 -08:00
report. Only string properties are sent correctly. Nested objects are not
2019-05-28 10:17:01 -07:00
supported. When using Windows, the property names and values must be fewer than 64 characters.
2019-06-21 16:19:21 -05:00
* `crashesDirectory` String (optional) - Directory to store the crash reports temporarily (only used when the crash reporter is started via `process.crashReporter.start` ).
2014-05-22 14:20:17 +02:00
2016-11-28 15:37:06 -08:00
You are required to call this method before using any other `crashReporter` APIs
2016-11-23 15:36:03 -08:00
and in each process (main/renderer) from which you want to collect crash reports.
2016-11-28 15:37:06 -08:00
You can pass different options to `crashReporter.start` when calling from different processes.
2016-11-23 15:36:03 -08:00
2017-02-02 13:01:49 -08:00
**Note** Child processes created via the `child_process` module will not have access to the Electron modules.
2017-01-17 21:59:23 -08:00
Therefore, to collect crash reports from them, use `process.crashReporter.start` instead. Pass the same options as above
along with an additional one called `crashesDirectory` that should point to a directory to store the crash
2017-01-24 14:04:56 -08:00
reports temporarily. You can test this out by calling `process.crash()` to crash the child process.
2017-01-17 21:59:23 -08:00
2017-02-09 12:47:02 -08:00
**Note:** If you need send additional/updated `extra` parameters after your
2018-02-20 08:26:10 -05:00
first call `start` you can call `addExtraParameter` on macOS or call `start`
2017-02-09 12:47:02 -08:00
again with the new/updated `extra` parameters on Linux and Windows.
2019-06-12 23:42:21 -07:00
**Note:** On macOS and windows, Electron uses a new `crashpad` client for crash collection and reporting.
2017-01-10 16:07:10 -08:00
If you want to enable crash reporting, initializing `crashpad` from the main process using `crashReporter.start` is required
2016-11-23 15:36:03 -08:00
regardless of which process you want to collect crashes from. Once initialized this way, the crashpad handler collects
2017-01-17 21:59:23 -08:00
crashes from all processes. You still have to call `crashReporter.start` from the renderer or child process, otherwise crashes from
them will get reported without `companyName` , `productName` or any of the `extra` information.
2015-05-30 10:03:59 +08:00
2015-08-25 05:01:57 -07:00
### `crashReporter.getLastCrashReport()`
2014-11-11 20:20:36 +08:00
2016-11-08 15:54:34 +11:00
Returns [`CrashReport` ](structures/crash-report.md ):
2016-09-25 12:59:30 +13:00
2019-03-20 15:34:21 -07:00
Returns 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.
2014-11-11 20:20:36 +08:00
2015-08-25 05:01:57 -07:00
### `crashReporter.getUploadedReports()`
2015-06-05 19:05:55 +08:00
2016-11-08 15:54:34 +11:00
Returns [`CrashReport[]` ](structures/crash-report.md):
2016-09-25 12:59:30 +13:00
2015-08-26 16:28:44 -07:00
Returns all uploaded crash reports. Each report contains the date and uploaded
ID.
2015-06-05 19:05:55 +08:00
2019-06-12 23:42:21 -07:00
### `crashReporter.getUploadToServer()`
2016-11-08 11:12:46 +11:00
2017-11-29 11:58:24 +01:00
Returns `Boolean` - Whether reports should be submitted to the server. Set through
2016-11-22 19:30:20 +11:00
the `start` method or `setUploadToServer` .
2016-11-08 11:12:46 +11:00
2016-11-28 15:03:38 -08:00
**Note:** This API can only be called from the main process.
2016-11-08 13:39:11 +13:00
2019-06-12 23:42:21 -07:00
### `crashReporter.setUploadToServer(uploadToServer)`
2016-11-08 11:03:57 +11:00
2017-11-29 11:38:35 +01:00
* `uploadToServer` Boolean _macOS_ - Whether reports should be submitted to the server.
2016-11-08 11:03:57 +11:00
2016-11-28 15:03:10 -08:00
This would normally be controlled by user preferences. This has no effect if
called before `start` is called.
2016-11-08 11:03:57 +11:00
2016-11-28 15:03:38 -08:00
**Note:** This API can only be called from the main process.
2016-11-08 13:39:11 +13:00
2019-06-12 23:42:21 -07:00
### `crashReporter.addExtraParameter(key, value)` _macOS_ _Windows_
2017-11-01 21:57:43 -04:00
* `key` String - Parameter key, must be less than 64 characters long.
* `value` String - Parameter value, must be less than 64 characters long.
Set an extra parameter to be sent with the crash report. The values
2019-06-12 23:42:21 -07:00
specified here will be sent in addition to any values set via the `extra` option when `start` was called. This API is only available on macOS and windows, if you need to add/update extra parameters on Linux after your first call to `start` you can call `start` again with the updated `extra` options.
2017-02-09 12:47:02 -08:00
2019-06-12 23:42:21 -07:00
### `crashReporter.removeExtraParameter(key)` _macOS_ _Windows_
2017-11-01 21:21:41 -04:00
* `key` String - Parameter key, must be less than 64 characters long.
Remove a extra parameter from the current set of parameters so that it will not be sent with the crash report.
### `crashReporter.getParameters()`
See all of the current parameters being passed to the crash reporter.
2016-11-21 15:42:24 -08:00
## Crash Report Payload
2014-05-22 14:20:17 +02:00
2016-04-22 22:53:26 +09:00
The crash reporter will send the following data to the `submitURL` as
a `multipart/form-data` `POST` :
2014-05-22 14:20:17 +02:00
2015-08-25 05:18:02 -07:00
* `ver` String - The version of Electron.
* `platform` String - e.g. 'win32'.
* `process_type` String - e.g. 'renderer'.
2017-11-29 11:38:35 +01:00
* `guid` String - e.g. '5e1286fc-da97-479e-918b-6bfb0c3d1c72'.
2015-08-25 05:18:02 -07:00
* `_version` String - The version in `package.json` .
2015-08-25 05:16:20 -07:00
* `_productName` String - The product name in the `crashReporter` `options`
2015-08-25 05:18:02 -07:00
object.
* `prod` String - Name of the underlying product. In this case Electron.
2015-08-25 05:16:20 -07:00
* `_companyName` String - The company name in the `crashReporter` `options`
2015-08-25 05:18:02 -07:00
object.
2016-03-17 22:29:32 +09: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.