crashReporter
Envía los informes de fallos a un servidor remoto.
El siguiente es un ejemplo de como configurar Electron para que envié automáticamente reportes de error a un servidor remoto:
const { crashReporter } = require('electron')
crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' })
Para configurar un servidor que acepte y procese los informes de fallos, se pueden utilizar los siguientes proyectos:
[!NOTE] Electron uses Crashpad, not Breakpad, to collect and upload crashes, but for the time being, the upload protocol is the same.
O utilice una solución alojada por terceros:
Crash reports are stored temporarily before being uploaded in a directory underneath the app's user data directory, called 'Crashpad'. You can override this directory by calling app.setPath('crashDumps', '/path/to/crashes')
before starting the crash reporter.
Electron usa crashpad para controlar e informar de fallos.
Métodos
El módulo crashReporter
tiene los siguientes métodos:
crashReporter.start(options)
Este método debe ser llamada antes de usar cualquier otra APIs crashReporter
. Una vez inicializado de esta manera, el crashpad handler recopila los fallos desde todos los procesos creados posteriormente. El crash reporter no puede ser desactiva una vez iniciado.
Este método debería ser llamado tan pronto como sea posible al iniciar la aplicación, preferentemente antes de app.on('ready')
. Si el crash reporter no está iniciado al tiempo que un renderer process este creado, entonces ese renderer process no será monitoreado por el 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 callstart
you can calladdExtraParameter
.
[!NOTE] Parameters passed in
extra
,globalExtra
or set withaddExtraParameter
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. Las llaves con nombres más largo que el máximo serán ignoradas de forma silenciosa. Key values longer than the maximum length will be truncated.
[!NOTE] This method is only available in the main process.
crashReporter.getLastCrashReport()
Returns CrashReport | null - The date and ID of the last crash report. Solo los reportes de fallos que han sido alzados serán retornados; incluso si un reporte de fallo esta presente en el disco este no sera retornado a menos que este alzado. En caso de que no haya reportes subidos, null
es retornado.
[!NOTE] This method is only available in the main process.
crashReporter.getUploadedReports()
Returns CrashReport[]:
Devuelve todos los informes de error subidos. Cada informe contiene la fecha y el ID con el que son subidos.
[!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 - Si los reportes deben enviarse o no al servidor.
This would normally be controlled by user preferences. This has no effect if called before start
is called.
[!NOTE] This method is only available in the main process.
crashReporter.addExtraParameter(clave, valor)
key
string - La clave del parámetro, debe tener menos de 39 bytes.key
string - La clave del parámetro, debe tener menos de 127 bytes.
Establecer un parámetro adicional que se enviará con el informe de fallos. Los valores especificados aquí serán enviados, adicionalmente cualquier valor establecidos a través de la opción extra
cuando fue llamado start
.
Los parámetros agregados de esta manera (o a través del parámetro extra
al crashReporter.start
) son específicos del proceso de llamada. Agregar parámetros extras en el main process no causarán que esos parámetros sean enviado junto con los fallos del renderer u otros procesos hijos. De manera similar, agregar parámetros extras en un renderer process no dará como resultado que esos parámetros sean enviados con los fallos que ocurren en otros renderer processes o en el main process.
[!NOTE] 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. Las llaves con nombres más largo que el máximo serán ignoradas de forma silenciosa. Key values longer than the maximum length will be truncated.
crashReporter.removeExtraParameter(clave)
key
string - La clave del parámetro, debe tener menos de 39 bytes.
Remove an extra parameter from the current set of parameters. Los fallos futuros no incluirán este parámetro.
crashReporter.getParameters()
Returns Record<string, string>
- The current 'extra' parameters of the crash reporter.
In Node 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.
process.crashReporter.start(options)
Note that if the crash reporter is started in the main process, it will automatically monitor child processes, so it should not be started in the child process. Utilize este método únicamente si el proceso principal no inicializa el crashReporter.
process.crashReporter.getParameters()
See crashReporter.getParameters()
.
process.crashReporter.addExtraParameter(key, value)
See crashReporter.addExtraParameter(key, value)
.
process.crashReporter.removeExtraParameter(key)
See crashReporter.removeExtraParameter(key)
.
Carga útil del informe de fallos
El informador de fallos enviará la siguiente información al submitURL
como un multipart/form-data
POST
:
ver
string - La versión de Electron.platform
string - por ejemplo, "win32".process_type
string - por ejemplo, "renderer".guid
string - por ejemplo, "5e1286fc-da97-479e-918b-6bfb0c3d1c72"._version
string - La versión enpackage.json
._productName
string - El nombre del producto en el objetocrashReporter
options
.prod
string - Nombre del producto subyacente. En esta caso Electron._companyName
string - El nombre de la empresa en el objetocrashReporter
options
.upload_file_minidump
Archivo - El informe de fallos en el formato deminidump
.- Todas las propiedades de nivel uno del objeto
extra
en el objetocrashReporter
options
.