支持的命令行开关
🌐 Supported Command Line Switches
Electron 支持的命令行开关。
你可以在 应用 模块触发 准备好了 事件之前,在应用的主脚本中使用 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.com、foobar.com、baz 结尾的 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.
此标志对所有渲染器进程都是全局的,如果你只想在一个窗口中禁用限流,你可以采用 播放静音音频 这种方法。
🌐 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 上,子进程的日志无法发送到标准错误输出。 在文件中记录日志是在 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 已弃用
🌐 --host-rules=rules Deprecated
一串由逗号分隔的 rules,用于控制主机名的映射方式。
🌐 A comma-separated list of rules that control how hostnames are mapped.
例如:
🌐 For example:
MAP * 127.0.0.1强制将所有主机名映射到 127.0.0.1MAP *.google.com proxy强制将所有 google.com 子域名解析到 “proxy”。MAP test.com [::1]:77强制将 "test.com" 解析为 IPv6 回环地址。同时还会将生成的套接字地址的端口强制设置为 77。MAP * baz, EXCLUDE www.google.com将所有内容重新映射到 "baz",除了 "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 开关。
--host-resolver-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.1MAP *.google.com proxy强制将所有 google.com 子域名解析到 “proxy”。MAP test.com [::1]:77强制将 "test.com" 解析为 IPv6 回环地址。同时还会将生成的套接字地址的端口强制设置为 77。MAP * baz, EXCLUDE www.google.com将所有内容重新映射到 "baz",除了 "www.google.com"。
这些 rules 仅适用于主机解析器。
🌐 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-options 或 electron --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.
--日志级别=N
🌐 --log-level=N
当与 --enable-logging 一起使用时,设置日志记录的详细程度。
N 应该是 Chrome 的日志严重性 中的一个。
🌐 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 complementary 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 沙箱。 强制渲染进程和 Chromium 辅助进程在无沙箱模式下运行。 应仅用于测试。
🌐 Disables the Chromium sandbox. Forces renderer process and Chromium helper processes to run un-sandboxed. Should only be used for testing.
--no-stdio-init
在节点初始化期间禁用 stdio 初始化。用于在 Windows 平台禁用 nul 设备时避免节点初始化崩溃。
🌐 Disable stdio initialization during node initialization. Used to avoid node initialization crash when the nul device is disabled on Windows platform.
--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')
将对除本地地址(localhost、127.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日志记录级别;默认值为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.
--xdg-portal-required-version=version
设置 XDG 门户实现所需的最低版本为 version,以便在 Linux 上使用文件对话框的门户后端。当所需版本不可用时,文件对话框将根据桌面环境回退使用 gtk 或 kde。当前默认设置为 3。
🌐 Sets the minimum required version of XDG portal implementation to version
in order to use the portal backend for file dialogs on linux. File dialogs
will fallback to using gtk or kde depending on the desktop environment when
the required version is unavailable. Current default is set to 3.
Node.js 标志
🌐 Node.js Flags
Electron 支持部分由 Node.js 支持的 命令行标志。
🌐 Electron supports some of the CLI flags supported by Node.js.
当 Electron 未在 ELECTRON_RUN_AS_NODE 中运行时,传递不支持的命令行开关将不会生效。
--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:port 是 127.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 开发者工具和 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.
--experimental-network-inspection
启用对 DevTools 网络检查器事件的支持,以便查看 nodejs http 和 https 模块发出的请求。
🌐 Enable support for DevTools network inspector events, for visibility into requests made by the nodejs http and https modules.
--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:设置默认的verbatimfalse。verbatim:设置默认的verbatimtrue。
默认情况下,verbatim 和 dns.setDefaultResultOrder() 的优先级高于 --dns-result-order。
🌐 The default is verbatim and dns.setDefaultResultOrder() have higher priority than --dns-result-order.
--diagnostic-dir=directory
设置所有 Node.js 诊断输出文件写入的目录。默认为当前工作目录。
🌐 Set the directory to which all Node.js diagnostic output files are written. Defaults to current working directory.
影响 v8.setHeapSnapshotNearHeapLimit 的默认输出目录。
🌐 Affects the default output directory of v8.setHeapSnapshotNearHeapLimit.
--no-experimental-global-navigator
禁止在 Node.js 的全局范围内暴露 导航器 API。
🌐 Disable exposition of Navigator API on the global scope from Node.js.
Chromium 标志
🌐 Chromium Flags
没有 Chromium 所有开关的完整文档列表,但有几种方法可以找到它们。
🌐 There isn't a documented list of all Chromium switches, but there are a few ways to find them.
最简单的方法是通过 Chromium 的 flags 页面,你可以在 about://flags 访问它。这些 flags 并不直接对应开关名称,但它们会出现在进程的命令行参数中。
🌐 The easiest way is through Chromium's flags page, which you can access at about://flags. These flags don't directly match switch names, but they show up in the process's command-line arguments.
要查看这些参数,请在 about://flags 中启用一个标志,然后在 Chromium 中转到 about://version。你会找到一份命令行参数的列表,其中包括 --flag-switches-begin --your --list --flag-switches-end,它包含了你已启用标志的开关列表。
🌐 To see these arguments, enable a flag in about://flags, then go to about://version in Chromium. You'll find a list of command-line arguments, including --flag-switches-begin --your --list --flag-switches-end, which contains the list of your flag enabled switches.
大多数标志作为 --enable-features= 的一部分,但有些是独立开关,例如 --enable-experimental-web-platform-features。
🌐 Most flags are included as part of --enable-features=, but some are standalone switches, like --enable-experimental-web-platform-features.
完整的标志列表可以在 Chromium 的标志元数据页面 中找到,但该列表包括平台、环境和 GPU 特定的过期或可能无法正常工作的标志,因此其中许多标志在每种情况下可能并不总是可用。
🌐 A complete list of flags exists in Chromium's flag metadata page, but this list includes platform, environment and GPU specific, expired and potentially non-functional flags, so many of them might not always work in every situation.
请注意,独立开关有时可以拆分为单独的功能,因此没有完整的开关列表。
🌐 Keep in mind that standalone switches can sometimes be split into individual features, so there's no fully complete list of switches.
最后,你需要确保 Electron 中的 Chromium 版本与你用于交叉引用开关的浏览器版本一致。
🌐 Finally, you'll need to ensure that the version of Chromium in Electron matches the version of the browser you're using to cross-reference the switches.
与 Electron 应用相关的 Chromium 功能
🌐 Chromium features relevant to Electron apps
AlwaysLogLOAFURL:为非 HTTP(s)、非 data、非 blob 的 URL(例如file:或自定义协议 URL)的long-animation-framePerformanceObserver事件启用脚本归属功能。