Skip to main content

支持的命令行开关

支持的命令行开关

¥Supported Command Line Switches

Electron 支持的命令行开关。

¥Command line switches supported by Electron.

你可以在 app 模块的 ready 事件发出之前使用 app.commandLine.appendSwitch 将它们附加到应用的主脚本中:

¥You can use app.commandLine.appendSwitch to append them in your app's main script before the ready event of the app module is emitted:

const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1')

app.whenReady().then(() => {
// Your code here
})

Electron CLI 标志

¥Electron CLI Flags

--auth-server-whitelist=url

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

¥A comma-separated list of servers for which integrated authentication is enabled.

例如:

¥For example:

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

那么任何以 example.comfoobar.combaz 结尾的 url 将被考虑进行集成身份验证。如果没有 * 前缀,则 URL 必须完全匹配。

¥then any url ending with example.com, foobar.com, baz will be considered for integrated authentication. Without * prefix the URL has to match exactly.

--auth-negotiate-delegate-whitelist=url

需要委派用户凭据的服务器的逗号分隔列表。如果没有 * 前缀,则 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

为 posix 平台禁用 NTLM v2,在其他地方没有影响。

¥Disables NTLM v2 for posix platforms, no effect elsewhere.

--disable-http-cache

禁用 HTTP 请求的磁盘缓存。

¥Disables the disk cache for HTTP requests.

--disable-http2

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

¥Disable HTTP/2 and SPDY/3.1 protocols.

--disable-renderer-backgrounding

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

¥Prevents Chromium from lowering the priority of invisible pages' renderer processes.

该标志对所有渲染器进程都是全局的,如果你只想在一个窗口中禁用限制,你可以采用 播放无声音频 的 hack。

¥This flag is global to all renderer processes, if you only want to disable throttling in one window, you can take the hack of playing silent audio.

--disk-cache-size=size

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

¥Forces the maximum disk space to be used by the disk cache, in bytes.

--enable-logging[=file]

将 Chromium 的日志记录打印到 stderr(或日志文件)。

¥Prints Chromium's logging to stderr (or a log file).

ELECTRON_ENABLE_LOGGING 环境变量与传递 --enable-logging 具有相同的效果。

¥The ELECTRON_ENABLE_LOGGING environment variable has the same effect as passing --enable-logging.

传递 --enable-logging 将导致日志打印在 stderr 上。传递 --enable-logging=file 将导致日志保存到 --log-file=... 指定的文件中,如果未指定 --log-file,则保存到用户数据目录中的 electron_debug.log 中。

¥Passing --enable-logging will result in logs being printed on stderr. Passing --enable-logging=file will result in logs being saved to the file specified by --log-file=..., or to electron_debug.log in the user-data directory if --log-file is not specified.

注意:在 Windows 上,子进程的日志无法发送到 stderr。记录到文件是在 Windows 上收集日志的最可靠方法。

¥Note: On Windows, logs from child processes cannot be sent to stderr. Logging to a file is the most reliable way to collect logs on Windows.

另请参见 --log-file--log-level--v--vmodule

¥See also --log-file, --log-level, --v, and --vmodule.

--force-fieldtrials=trials

强制启用或禁用字段试验。

¥Field trials to be forcefully enabled or disabled.

例如:WebRTC-Audio-Red-For-Opus/Enabled/

¥For example: WebRTC-Audio-Red-For-Opus/Enabled/

--host-rules=rules

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

¥A comma-separated list of rules that control how hostnames are mapped.

例如:

¥For example:

  • MAP * 127.0.0.1 强制所有主机名映射到 127.0.0.1

    ¥MAP * 127.0.0.1 Forces all hostnames to be mapped to 127.0.0.1

  • MAP *.google.com proxy 强制将所有 google.com 子域解析为 "proxy"。

    ¥MAP *.google.com proxy Forces all google.com subdomains to be resolved to "proxy".

  • MAP test.com [::1]:77 强制 "test.com" 解析为 IPv6 环回。还将强制生成的套接字地址的端口为 77。

    ¥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”除外。

    ¥MAP * baz, EXCLUDE www.google.com Remaps everything to "baz", except for "www.google.com".

这些映射适用于网络请求中的端点主机(直接连接中的 TCP 连接和主机解析程序、HTTP 代理连接中的 CONNECT 以及 SOCKS 代理连接中的端点主机)。

¥These mappings apply to the endpoint host in a net request (the TCP connect and host resolver in a direct connection, and the CONNECT in an HTTP proxy connection, and the endpoint host in a SOCKS proxy connection).

--host-resolver-rules=rules

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

¥Like --host-rules but these rules only apply to the host resolver.

--ignore-certificate-errors

忽略与证书相关的错误。

¥Ignores certificate related errors.

--ignore-connections-limit=domains

忽略由 , 分隔的 domains 列表的连接限制。

¥Ignore the connections limit for domains list separated by ,.

--js-flags=flags

指定传递给 V8 发动机 的标志。为了在主进程中启用 flags,必须在启动时传递此开关。

¥Specifies the flags passed to the V8 engine. In order to enable the flags in the main process, this switch must be passed on startup.

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

在终端中运行 node --v8-optionselectron --js-flags="--help" 以获得可用标志的列表。这些可用于启用早期 JavaScript 功能,或记录和操作垃圾收集等。

¥Run node --v8-options or electron --js-flags="--help" in your terminal for the list of available flags. These can be used to enable early-stage JavaScript features, or log and manipulate garbage collection, among other things.

例如,跟踪 V8 优化和反优化:

¥For example, to trace V8 optimization and deoptimization:

$ electron --js-flags="--trace-opt --trace-deopt" your-app

--lang

设置自定义区域设置。

¥Set a custom locale.

--log-file=path

如果指定 --enable-logging,日志将写入给定路径。父目录必须存在。

¥If --enable-logging is specified, logs will be written to the given path. The parent directory must exist.

设置 ELECTRON_LOG_FILE 环境变量相当于传递此标志。如果两者都存在,则命令行开关优先。

¥Setting the ELECTRON_LOG_FILE environment variable is equivalent to passing this flag. If both are present, the command-line switch takes precedence.

--log-net-log=path

允许保存网络日志事件并将其写入 path

¥Enables net log events to be saved and writes them to path.

--log-level=N

--enable-logging 一起使用时设置日志记录的详细程度。N 应该是 Chrome 的 LogSeverities 之一。

¥Sets the verbosity of logging when used together with --enable-logging. N should be one of Chrome's LogSeverities.

请注意,Chromium 中的两种免费日志记录机制(LOG()VLOG())由不同的开关控制。--log-level 控制 LOG() 消息,而 --v--vmodule 控制 VLOG() 消息。因此,你可能需要使用这三个开关的组合,具体取决于你想要的粒度以及你要监视的代码进行的日志记录调用。

¥Note that two complimentary logging mechanisms in Chromium -- LOG() and VLOG() -- are controlled by different switches. --log-level controls LOG() messages, while --v and --vmodule control VLOG() messages. So you may want to use a combination of these three switches depending on the granularity you want and what logging calls are made by the code you're trying to watch.

有关 LOG()VLOG() 如何交互的更多信息,请参阅 Chromium 日志记录源。宽松地说,VLOG() 可以被认为是 LOG(INFO) 内部的子级别/每个模块级别,用于控制 LOG(INFO) 数据的流水。

¥See Chromium Logging source for more information on how LOG() and VLOG() interact. Loosely speaking, VLOG() can be thought of as sub-levels / per-module levels inside LOG(INFO) to control the firehose of LOG(INFO) data.

另请参见 --enable-logging--log-level--v--vmodule

¥See also --enable-logging, --log-level, --v, and --vmodule.

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

禁用 Chromium sandbox。强制渲染器进程和 Chromium 辅助进程在非沙盒环境下运行。应该仅用于测试。

¥Disables the Chromium sandbox. Forces renderer process and Chromium helper processes to run un-sandboxed. Should only be used for testing.

--proxy-bypass-list=hosts

指示 Electron 绕过给定的以分号分隔的主机列表的代理服务器。该标志仅在与 --proxy-server 一起使用时才有效。

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

例如:

¥For example:

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

将为所有主机使用代理服务器,本地地址(localhost127.0.0.1 等)、google.com 子域、包含后缀 foo.com 的主机以及 1.2.3.4:5678 中的任何内容除外。

¥Will use the proxy server for all hosts except for local addresses (localhost, 127.0.0.1 etc.), google.com subdomains, hosts that contain the suffix foo.com and anything at 1.2.3.4:5678.

--proxy-pac-url=url

在指定的 url 使用 PAC 脚本。

¥Uses the PAC script at the specified url.

--proxy-server=address:port

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

¥Use a specified proxy server, which overrides the system setting. This switch only affects requests with HTTP protocol, including HTTPS and WebSocket requests. It is also noteworthy that not all proxy servers support HTTPS and WebSocket requests. The proxy URL does not support username and password authentication per Chromium issue.

--remote-debugging-port=port

在指定的 port 上启用通过 HTTP 的远程调试。

¥Enables remote debugging over HTTP on the specified port.

--v=log_level

给出默认的最大活动 V-logging 级别;0 是默认值。通常正值用于 V 记录级别。

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

该开关仅在 --enable-logging 也通过时才起作用。

¥This switch only works when --enable-logging is also passed.

另请参见 --enable-logging--log-level--vmodule

¥See also --enable-logging, --log-level, and --vmodule.

--vmodule=pattern

给出每个模块的最大 V 记录级别以覆盖 --v 给出的值。例如。my_module=2,foo*=3 将更改源文件 my_module.*foo*.* 中所有代码的日志记录级别。

¥Gives the per-module maximal V-logging levels to override the value given by --v. E.g. my_module=2,foo*=3 would change the logging level for all code in source files my_module.* and foo*.*.

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

¥Any pattern containing a forward or backward slash will be tested against the whole pathname and not only the module. E.g. */foo/bar/*=2 would change the logging level for all code in the source files under a foo/bar directory.

该开关仅在 --enable-logging 也通过时才起作用。

¥This switch only works when --enable-logging is also passed.

另请参见 --enable-logging--log-level--v

¥See also --enable-logging, --log-level, and --v.

--force_high_performance_gpu

当有多个可用 GPU 时,强制使用独立 GPU。

¥Force using discrete GPU when there are multiple GPUs available.

--force_low_power_gpu

当有多个可用 GPU 时强制使用集成 GPU。

¥Force using integrated GPU when there are multiple GPUs available.

Node.js 标志

¥Node.js Flags

Electron 支持 Node.js 支持的一些 CLI 标志

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

注意:当 Electron 未在 ELECTRON_RUN_AS_NODE 中运行时,将不受支持的命令行开关传递给 Electron 将不会产生任何效果。

¥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]

在主机上激活检查器:端口并在用户脚本开始时中断。默认主机:端口为 127.0.0.1:9229。

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

别名为 --debug-brk=[host:]port

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

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

host:port 上激活检查器,并在检查器可用时在执行的第一个内部 JavaScript 脚本开始时中断。默认 host:port127.0.0.1:9229

¥Activate inspector on host:port and break at start of the first internal JavaScript script executed when the inspector is available. Default host:port is 127.0.0.1:9229.

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

设置激活检查器时要使用的 host:port。通过发送 SIGUSR1 信号激活检查器时很有用。默认主机是 127.0.0.1

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

别名为 --debug-port=[host:]port

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

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

激活 host:port 上的检查器。默认为 127.0.0.1:9229

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

V8 检查器集成允许 Chrome DevTools 和 IDE 等工具来调试和分析 Electron 实例。这些工具通过 TCP 端口连接到 Electron 实例,并使用 Chrome 开发者工具协议 进行通信。

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

有关详细信息,请参阅 调试主进程 指南。

¥See the Debugging the Main Process guide for more details.

别名为 --debug[=[host:]port

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

--inspect-publish-uid=stderr,http

指定检查器 Web 套接字 url 暴露的方式。

¥Specify ways of the inspector web socket url exposure.

默认情况下,检查器 websocket url 在 stderr 和 http://host:port/json/list 上的 /json/list 端点下可用。

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

--no-deprecation

静默弃用警告。

¥Silence deprecation warnings.

--throw-deprecation

抛出弃用错误。

¥Throw errors for deprecations.

--trace-deprecation

打印弃用的堆栈跟踪。

¥Print stack traces for deprecations.

--trace-warnings

打印进程警告的堆栈跟踪(包括弃用)。

¥Print stack traces for process warnings (including deprecations).

--dns-result-order=order

设置 Node.js dns.lookup()dnsPromises.lookup() 函数中 verbatim 参数的默认值。该值可以是:

¥Set the default value of the verbatim parameter in the Node.js dns.lookup() and dnsPromises.lookup() functions. The value could be:

  • ipv4first:设置默认 verbatim false

    ¥ipv4first: sets default verbatim false.

  • verbatim:设置默认 verbatim true

    ¥verbatim: sets default verbatim true.

默认为 verbatimdns.setDefaultResultOrder() 的优先级高于 --dns-result-order

¥The default is verbatim and dns.setDefaultResultOrder() have higher priority than --dns-result-order.