Saltar al contenido principal

Variables de entorno

Configuración y comportamiento de la aplicación de control sin cambiar el código.

Ciertos comportamientos de Electron están controlados por variables de entorno debido a que son inicializadas antes que las flags de la línea de comandos y que el código de la applicación.

Ejemplo de shell POSIX:

$ export ELECTRON_ENABLE_LOGGING=true
$ electron

Ejemplo de la consola de Windows:

> set ELECTRON_ENABLE_LOGGING=true
> electron

Variables de producción​

Las siguientes variables de entorno están diseñadas principalmente para usarse en los módulos de ejecución en las aplicaciones preconfiguradas de Electron.

NODE_OPTIONS​

Electron incluye soporte para un subconjunto de NODE_OPTIONS de Node. La mayoría son soportadas con la excepción de aquellos que entran en conflicto con el uso de BoringSSL de Chromium.

Ejemplo:

export NODE_OPTIONS="--no-warnings --max-old-space-size=2048"

Las opciones no respaldadas son:

--use-bundled-ca
--force-fips
--enable-fips
--openssl-config
--use-openssl-ca

NODE_OPTIONS están explícitamente deshabilitadas en las aplicaciones empaquetadas, excepto para lo siguiente:

--max-http-header-size
--http-parser

Si el nodeOptions fusible está desactivado, NODE_OPTIONS será ignorado.

NODE_EXTRA_CA_CERTS​

See Node.js cli documentation for details.

export NODE_EXTRA_CA_CERTS=/path/to/cert.pem

Si el nodeOptions fusible está desactivado, NODE_EXTRA_CA_CERTS será ignorado.

GOOGLE_API_KEY​

El soporte de geolocalización en Electron requiere el uso del servicio web de Google Cloud Platform. Para habilitar esta función, adquiera una Google API key y coloque el siguiente código en su archivo de proceso principal, antes de abrir cualquier ventana de buscador que vaya a realizar solicitudes de geolocalización:

process.env.GOOGLE_API_KEY = 'TU_CLAVE_AQUI'

Por defecto, una clave API de Google recientemente generada podría no tener permitido hacer solicitudes de geolocalización. Para habilitar el servicio web de geolocalización para su proyecto, habilítelo a través de la API library.

N.B. You will need to add a Billing Account to the project associated to the API key for the geolocation webservice to work.

ELECTRON_NO_ASAR​

Disables ASAR support. This variable is only supported in forked child processes and spawned child processes that set ELECTRON_RUN_AS_NODE.

ELECTRON_RUN_AS_NODE​

Inicia el proceso como un proceso normal de Node.js.

En este modo, podrás ser capaz de pasar opciones cli a Node.js como lo harías cuando corres el ejecutable normal de Node.js, con la excepción de las siguientes banderas:

  • "--openssl-config"
  • "--use-bundled-ca"
  • "--use-openssl-ca",
  • "--force-fips"
  • "--enable-fips"

These flags are disabled owing to the fact that Electron uses BoringSSL instead of OpenSSL when building Node.js' crypto module, and so will not work as designed.

Si el runAsNode fusible está desactivado, ELECTRON_RUN_AS_NODE será ignorado.

ELECTRON_NO_ATTACH_CONSOLE Windows​

No se adjunta a la sesión de la consola actual.

ELECTRON_FORCE_WINDOW_MENU_BAR Linux​

No utilizar la barra de menú global en Linux.

ELECTRON_TRASH Linux​

Set the trash implementation on Linux. Por defecto es gio.

Opciones:

  • gvfs-trash
  • trash-cli
  • kioclient5
  • kioclient

Variables de desarrollo​

Las siguientes variables de entorno están principalmente diseñadas para propósitos de desarrollo y depuración.

ELECTRON_ENABLE_LOGGING​

Prints Chromium's internal logging to the console.

Setting this variable is the same as passing --enable-logging on the command line. For more info, see --enable-logging in command-line switches.

ELECTRON_LOG_FILE​

Sets the file destination for Chromium's internal logging.

Setting this variable is the same as passing --log-file on the command line. For more info, see --log-file in command-line switches.

ELECTRON_DEBUG_NOTIFICATIONS​

Adds extra logs to Notification lifecycles on macOS to aid in debugging. Se mostrará un registro adicional cuando se creen o activen nuevas notificaciones. También se mostraran cuando acciones comunes son realizadas: se muestra una notificación, se descarga, su botón es pulsado, o responde a.

Ejemplo de salida:

Notification created (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification displayed (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification activated (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification replied to (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)

ELECTRON_DEBUG_MSIX_UPDATER​

Adds extra logs to MSIX updater operations on Windows to aid in debugging. Extra logging will be displayed when MSIX update operations are initiated, including package updates, package registration, and restart registration. This helps diagnose issues with MSIX package updates and deployments.

Ejemplo de salida:

UpdateMsix called with URI: https://example.com/app.msix
DoUpdateMsix: Starting
Calling AddPackageByUriAsync... URI: https://example.com/app.msix
Update options - deferRegistration: true, developerMode: false, forceShutdown: false, forceTargetShutdown: false, forceUpdateFromAnyVersion: false
Waiting for deployment...
Deployment finished.
MSIX Deployment completed.

ELECTRON_DEBUG_DRAGGABLE_REGIONS Experimental​

[!WARNING] This variable is a debugging aid, not part of Electron's formal API. It is experimental and its behavior, output, or existence may change or be removed in any release without warning.

Visualizes and logs the draggable regions of every window to aid in debugging custom title bars. Only takes effect when app.isPackaged is false.

When set, the region that Electron hit tests against for each WebContents (the union of every app-region: drag rectangle minus every app-region: no-drag rectangle, as computed by the renderer) is painted as translucent red rectangles floating above the web contents, with the parts that changed in the latest update tinted yellow. The overlay ignores mouse events and follows the web contents as it moves or resizes. It reflects the region the main process actually uses rather than the CSS in the page, so it can lag behind the page while regions are in flight from the renderer; the stamp in its corner shows which update it is painting.

Extra logs are also written whenever the renderer sends a new set of regions, whenever the web contents changes size, and, every couple of seconds, a summary of the hit tests served against the region. Logging must be enabled, for example with ELECTRON_ENABLE_LOGGING, for these to be displayed.

Ejemplo de salida:

[draggable-regions] webContents 1: debugging enabled
[draggable-regions] webContents 1: update #1: renderer sent 5 region(s) (1 drag, 4 no-drag); hit-test region computed in 3.2 us: 6 rect(s), bounds 0,0 1200x40
[draggable-regions] webContents 1: contents view bounds changed to 464,245 1280x720, 8.3 ms since previous bounds change; overlay still shows update #1
[draggable-regions] webContents 1: update #2, 16.4 ms since previous update, 7.1 ms after last bounds change to 1280x720: renderer sent 5 region(s) (1 drag, 4 no-drag); hit-test region computed in 2.8 us: 6 rect(s), bounds 0,0 1280x40
[draggable-regions] webContents 1: 143 hit test(s) in the last 2.0 s (37 inside a draggable region), total 41.5 us, avg 0.3 us, max 1.9 us

ELECTRON_LOG_ASAR_READS​

When Electron reads from an ASAR file, log the read offset and file path to the system tmpdir. The resulting file can be provided to the ASAR module to optimize file ordering. This variable is read once when each process starts, so it must be set in the environment that launches Electron rather than from the app's own code.

ELECTRON_ENABLE_STACK_DUMPING​

Imprime el rastro de la pila a la consola cuando Electron falla.

Esta variable de entorno no funcionará si se inicia el crashReporter.

ELECTRON_DEFAULT_ERROR_MODE Windows​

Muestra el cuadro de dialogo del fallo de Windows cuando falla Electron.

Esta variable de entorno no funcionará si se inicia el crashReporter.

ELECTRON_OVERRIDE_DIST_PATH​

Cuando corre desde el paquete electron, esta variable dice al comando electron para usar la instancia especificada del constructor de Electron en lugar de uno descargado por npm install. Uso:

export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing

ELECTRON_INSTALL_PLATFORM​

Manually overrides platform used by electron package during an install. This can be useful if you are on one platform (e.g macOS) but want to download binaries for another platform (e.g Windows or Linux). Uso:

ELECTRON_INSTALL_PLATFORM=darwin npm install

ELECTRON_INSTALL_ARCH​

Manually overrides architecture used by electron package during an install. This can be useful if you are on one arch (e.g arm64) but want to download binaries meant for another arch. Note that this will not work under Rosetta. Uso:

ELECTRON_INSTALL_ARCH=arm64 npm install