Перейти к основному содержанию

Переменные окружения

Управляй настройкой приложения и его поведением без изменения кода.

Некоторые поведения Electron управляются переменными окружения, потому что они инициализируются раньше, чем флаги командной строки и код приложения.

Пример терминала POSIX:

$ export ELECTRON_ENABLE_LOGGING=true
$ electron

Пример терминала Windows:

> set ELECTRON_ENABLE_LOGGING=true
> electron

Переменные production

Следующие переменные окружения предназначены для использования в среде выполнения приложения Electron.

NODE_OPTIONS

Electron включает поддержку подмножества Node's NODE_OPTIONS. Большинство поддерживаются за исключением тех, которые конфликтуют с использованием Chromium BoringSSL.

Пример:

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

Неподдерживаемые опции:

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

NODE_OPTIONS are explicitly disallowed in packaged apps, except for the following:

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

GOOGLE_API_KEY

Поддержка геолокации в Electron требует использования сервиса геолокации Google Cloud Platform. Для включения этой функции получите Ключ Google API и поместите следующий код в ваш файл основного процесса перед открытием любых окон браузера, делающим запросы геолокации:

process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE'

По умолчанию, новый сгенерированный ключ API Google не может делать запросы геолокации. Чтобы включить веб-сервис геолокации для вашего проекта требуется библиотека API.

Обратите внимание. 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

Отключает поддержку ASAR. Данная переменная поддерживается только в дочерних процессах, которые установили переменную окружения ELECTRON_RUN_AS_NODE.

ELECTRON_RUN_AS_NODE

Начинает процесс как Node.js процесс.

In this mode, you will be able to pass cli options to Node.js as you would when running the normal Node.js executable, with the exception of the following flags:

  • "--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.

ELECTRON_NO_ATTACH_CONSOLE Windows

Не присоединяться к текущей сессии терминала.

ELECTRON_FORCE_WINDOW_MENU_BAR Linux

Не использовать глобальное меню в Linux.

ELECTRON_TRASH Linux

Set the trash implementation on Linux. По умолчанию - gio.

Параметры:

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

ELECTRON_OZONE_PLATFORM_HINT Linux

Selects the preferred platform backend used on Linux. The default one is x11. auto selects Wayland if possible, X11 otherwise.

Параметры:

  • auto
  • wayland
  • x11

Переменные разработки (development)

Следующие переменные окружения предназначены для использования в среде выполнения приложения Electron во время разработки и отладки.

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_DRAG_REGIONS

Adds coloration to draggable regions on BrowserViews on macOS - draggable regions will be colored green and non-draggable regions will be colored red to aid debugging.

ELECTRON_DEBUG_NOTIFICATIONS

Adds extra logs to Notification lifecycles on macOS to aid in debugging. Extra logging will be displayed when new Notifications are created or activated. They will also be displayed when common actions are taken: a notification is shown, dismissed, its button is clicked, or it is replied to.

Sample output:

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_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.

ELECTRON_ENABLE_STACK_DUMPING

Выводит содержимое стэка в консоль при сбое Electron приложения.

Данная переменная окружения не будет работать, если crashReporter запущен.

ELECTRON_DEFAULT_ERROR_MODE Windows

Показывает диалог сбоя Windows при сбое Electron приложения.

Данная переменная окружения не будет работать, если crashReporter запущен.

ELECTRON_OVERRIDE_DIST_PATH

При запуске из electron пакета, эта переменная дает команду electron использовать указанную сборку Electron вместо загруженной по npm install. Использование:

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

Set By Electron

Electron sets some variables in your environment at runtime.

ORIGINAL_XDG_CURRENT_DESKTOP

This variable is set to the value of XDG_CURRENT_DESKTOP that your application originally launched with. Electron sometimes modifies the value of XDG_CURRENT_DESKTOP to affect other logic within Chromium so if you want access to the original value you should look up this environment variable instead.