crashReporter
Soumet un rapport de plantage à un serveur distant.
Voici un exemple d'envoi automatique d'un rapport de plantage à un serveur distant :
const { crashReporter } = require('electron')
crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' })
Pour configurer un serveur pour accepter et traiter les rapports de plantage, vous pouvez utiliser les projets suivants :
Note : Electron utilise Crashpad et non Breakpad pour collecter and enregistrer les crashs, mais pour le moment le protocole d'upload est le même .
Ou utilisez une solution hébergée par un tiers :
Les rapports de plantage sont stockés temporairement avant d'être téléchargés dans un répertoire sous le répertoire de données utilisateur de l'application, appelé 'Crashpad'. You can override this directory by calling app.setPath('crashDumps', '/path/to/crashes')
before starting the crash reporter.
Electron utilise crashpad pour surveiller et signaler les plantages.
Méthodes
Le module crashReporter
dispose des méthodes suivantes :
crashReporter.start(options)
- Objet
options
submitURL
string (optional) - URL that crash reports will be sent to as POST. Required unlessuploadToServer
isfalse
.productName
string (facultatif) -app.name
.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. La valeur par défaut estvraie
.ignoreSystemCrashHandler
boolean (optional) - If true, crashes generated in the main process will not be forwarded to the system crash handler. Par défaut la valeur estfalse
.rateLimit
boolean (optional) macOS Windows - If true, limit the number of crashes uploaded to 1/hour. Par défaut la valeur estfalse
.compress
boolean (optional) - If true, crash reports will be compressed and uploaded withContent-Encoding: gzip
. La valeur par défaut estvraie
.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, calladdExtraParameter
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.
Cette méthode doit être appelée avant d'utiliser d'autres API crashReporter
. 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: This method is only available in the main process.
crashReporter.getLastCrashReport()
Returns CrashReport
- 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. Dans le cas où il n'y a pas de rapports téléchargés, null
est retourné.
Note: This method is only available in the main process.
crashReporter.getUploadedReports()
Retourne CrashReport[]
:
Returns all uploaded crash reports. Each report contains the date and uploaded ID.
Note: This method is only available in the main process.
crashReporter.getUploadToServer()
Returns boolean
- Whether reports should be submitted to the server. Set through the start
method or setUploadToServer
.
Note: This method is only available in the main process.
crashReporter.setUploadToServer(uploadToServer)
uploadToServer
boolean - Whether reports should be submitted to the server.
Cela devrait normalement être contrôlé par les préférences de l’utilisateur. This has no effect if called before start
is called.
Note: This method is only available in the main process.
crashReporter.addExtraParameter(key, value)
key
string - Parameter key, must be no longer than 39 bytes.value
string - Parameter value, must be no longer than 127 bytes.
Définit un paramètre supplémentaire à envoyer avec le rapport de plantage. The values specified here will be sent in addition to any values set via the extra
option when start
was called.
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.
Remarque : Les paramètres ont des limites sur la longueur des clés et des valeurs. 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 will be silently ignored. Key values longer than the maximum length will be truncated.
crashReporter.removeExtraParameter(key)
key
string - 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.
Dans les processus enfants node
Since require('electron')
is not available in Node child processes, the following APIs are available on the process
object in Node child processes.
process.crashReporter.start(options)
Voir crashReporter.start()
.
Notez que si le rapporteur de plantage est démarré dans le processus principal, il surveillera automatiquement les processus fils, donc il ne devrait pas être démarré dans le processus fils. Only use this method if the main process does not initialize the crash reporter.
process.crashReporter.getParameters()
Voir crashReporter.getParameters()
.
process.crashReporter.addExtraParameter(key, value)
Voir crashReporter.addExtraParameter(key, value)
.
process.crashReporter.removeExtraParameter(key)
Voir crashReporter.removeExtraParameter(key)
.
Payload du Crash Report
Le rapporteur de plantage enverra les données suivantes à submitURL
comme un POST
en multipart/form-data
:
ver
string - La version d'Electron.platform
string - Par exemple 'win32'.process_type
string - Par exemple 'renderer'.guid
string - Par exemple '5e1286fc-da97-479e-918b-6bfb0c3d1c72'._version
string - La version danspackage.json
._productName
string - Le nom du produit dans l'objetoptions
decrashReporter
.prod
string - Nom du produit sous-jacent. Dans ce cas, Electron._companyName
string - Le nom de l'entreprise dans l'objetoptions
decrashReporter
.upload_file_minidump
File - Le rapport d'incident dans le formatminidump
.- Toutes les propriétés de niveau 1 de l'objet
extra
dans l'objetoptions
decrashReporter
.