支持的命令行开关

Electron支持的命令行开关.

您可以在app 模块的ready事件生效之前,使用app.commandLine.appendSwitch将它们附加到您的应用程序的主要脚本中:

  1. const { app } = require('electron')
  2. app.commandLine.appendSwitch('remote-debugging-port', '8315')
  3. app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1')
  4. app.whenReady().then(() => {
  5. // Your code here
  6. })

Electron CLI Flags

--auth-server-whitelist=url

启用了集成身份验证的以逗号分隔的服务器列表。

例如:

  1. --auth-server-whitelist='*example.com, *foobar.com, *baz'

则任何以example.com, foobar.com, baz结尾的url, 都需要考虑集成验证. Without * prefix the URL has to match exactly.

--auth-negotiate-delegate-whitelist=url

A comma-separated list of servers for which delegation of user credentials is required. Without * prefix the URL has to match exactly.

--disable-ntlm-v2

Disables NTLM v2 for posix platforms, no effect elsewhere.

--disable-http-cache

禁用HTTP请求的磁盘缓存.

--disable-http2

禁用HTTP/2和SPDY/3.1协议.

--disable-renderer-backgrounding

防止Chromium降低不可见的页面渲染进程的优先级.

这个标识是全局的, 影响所有渲染进程. 如果你只想禁用一个窗口的节流保护,你可以采取playing silent audio.

--disk-cache-size=size

强制磁盘缓存使用的最大磁盘空间(以字节为单位)。

--enable-api-filtering-logging

Enables caller stack logging for the following APIs (filtering events):

  • desktopCapturer.getSources() / desktop-capturer-get-sources
  • remote.require() / remote-require
  • remote.getGlobal() / remote-get-builtin
  • remote.getBuiltin() / remote-get-global
  • remote.getCurrentWindow() / remote-get-current-window
  • remote.getCurrentWebContents() / remote-get-current-web-contents

--enable-logging

在控制台打印Chromium日志.

这个开关不能用于app.commandLine.appendSwitch, 因为它在用户应用程序加载之前就被解析了, 但是你可以设置ELECTRON_ENABLE_LOGGING环境变量来达到同样的效果.

--host-rules=rules

以逗号分隔的rules列表,用于控制主机名的映射方式

例如:

  • MAP * 127.0.0.1 强制将所有主机名映射到127.0.0.1
  • MAP *.google.com proxy 强制所有google.com子域名解析到”proxy”.
  • MAP test.com [::1]:77 Forces “test.com” to resolve to IPv6 loopback. Will also force the port of the resulting socket address to be 77.
  • MAP * baz, EXCLUDE www.google.com 把所有地址重新映射到“baz”, 除了”www.google.com”.

这些映射适用于网络请求中的端点主机. 网络请求包括TCP连接和直连的主机解析器, 以及HTTP代理连接中的CONNECT方式, 以及在SOCKS代理连接中的端点主机.

--host-resolver-rules=rules

--host-rules类似, 但是这些rules仅适用于主机解析器.

--ignore-certificate-errors

忽略证书相关的错误.

--ignore-connections-limit=domains

忽略由,分割的domains列表的连接限制.

--js-flags=flags

Specifies the flags passed to the Node.js engine. It has to be passed when starting Electron if you want to enable the flags in the main process.

  1. $ electron --js-flags="--harmony_proxies --harmony_collections" your-app

See the Node.js documentation or run node --help in your terminal for a list of available flags. Additionally, run node --v8-options to see a list of flags that specifically refer to Node.js’s V8 JavaScript engine.

--lang

设置系统语言环境

--log-net-log=path

启用需要保存的网络日志事件并将其写入path路径下.

--no-proxy-server

Don’t use a proxy server and always make direct connections. Overrides any other proxy server flags that are passed.

--no-sandbox

Disables Chromium sandbox, which is now enabled by default. Should only be used for testing.

--proxy-bypass-list=hosts

Instructs Electron to bypass the proxy server for the given semi-colon-separated list of hosts. This flag has an effect only if used in tandem with --proxy-server.

例如:

  1. const { app } = require('electron')
  2. app.commandLine.appendSwitch('proxy-bypass-list', '<local>;*.google.com;*foo.com;1.2.3.4:5678')

上面的代码, 除了本地地址(localhost,127.0.0.1等等.), google.com子域名, 包含foo.com后缀的主机地址, 以及任何在1.2.3.4:5678上的地址以外的所有主机都将使用代理服务器.

--proxy-pac-url=url

在指定url中使用PAC脚本.

--proxy-server=address:port

使用指定的覆盖系统设置的代理服务器. 这个开关只影响HTTP协议请求, 包括HTTPS和WebSocket请求. 值得注意的是并不是所有的代理服务器都支持HTTPS和WebSocket请求. 代理 URL 不支持用户名和密码认证方式 Chromium 的问题

--remote-debugging-port=port

在指定端口开启HTTP远程调试.

--v=log_level

Gives the default maximal active V-logging level; 0 is the default. Normally positive values are used for V-logging levels.

这个开关只有在--enable-logging也被传递时才起效.

--vmodule=pattern

给定每个模块最大的V-logging等级, 覆盖--v设定的值. 例如, my_module=2,foo*=3将改变所有my_module.*foo*.*源文件的代码的日志等级.

任何包含正斜杠或反斜杠的模式都将针对 整个路径名进行测试,而不仅仅是模块。 例如, */foo/bar/*=2会改变foo/bar目录下源文件的所有代码的日志等级.

这个开关只有在--enable-logging也被传递时才起效.

--force_high_performance_gpu

Force using discrete GPU when there are multiple GPUs available.

--force_low_power_gpu

Force using integrated GPU when there are multiple GPUs available.

Node.js Flags

Electron supports some of the CLI flags supported by Node.js.

Note: Passing unsupported command line switches to Electron when it is not running in ELECTRON_RUN_AS_NODE will have no effect.

--inspect-brk[=[host:]port]

Activate inspector on host:port and break at start of user script. Default host:port is 127.0.0.1:9229.

Aliased to --debug-brk=[host:]port.

--inspect-port=[host:]port

Set the host:port to be used when the inspector is activated. Useful when activating the inspector by sending the SIGUSR1 signal. Default host is 127.0.0.1.

Aliased to --debug-port=[host:]port.

--inspect[=[host:]port]

Activate inspector on host:port. Default is 127.0.0.1:9229.

V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug and profile Electron instances. The tools attach to Electron instances via a TCP port and communicate using the Chrome DevTools Protocol.

调试相关的标识, 更多详细信息请查看 Debugging the Main Process指南。

Aliased to --debug[=[host:]port.

--inspect-publish-uid=stderr,http

Specify ways of the inspector web socket url exposure.

By default inspector websocket url is available in stderr and under /json/list endpoint on http://host:port/json/list.