In this section, let's take a look at the command line switches supported in the Chrome browser and Electron We can develop these command lines ready event of the app module is app.commandLine.appendSwitch to add them to the application's main script.

Example:

For example, add a remote-debugging-port to the application's main script:

const app = require('electron').app;
// 添加命令行开关到脚本
app.commandLine.appendSwitch('remote-debugging-port', '8315');

app.on('ready', function() {
  // ...
});

Command line switch

Below we are some commonly used command line switches supported by Electron

--auth-server-whitelist=url

A comma-separated list of servers with integrated authentication enabled.

E.g:

--auth-server-whitelist='*example.com, *9xkd.com, *jswui'

The above code means that any jswui ending example.com , 9xkd.com , url , need to consider integrated verification. If there is no * prefix, url must match exactly.

--enable-api-filtering-logging

Enable caller stack logging (filtered events) for the following API

  • 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
--client-certificate=path

This command line switch is used to set the client certificate file path .

--ignore-connections-limit=domains

This command line switch can ignore the connection limit of the domains ,

--disable-http-cache

Used to prohibit the use of disk cache when HTTP

--remote-debugging-port=port

Used to enable remote debugging HTTP

--js-flags=flags

Used to specify the engine to transition to the JS engine.

When starting Electron , if we want to activate flags in the main process, it will be converted.

$ electron --js-flags="--harmony_proxies --harmony_collections" your-app
--proxy-server=address:port

Use a specific proxy server, it will be higher priority than the system settings, this switch is only valid when using the HTTP protocol, it contains HTTPS and WebSocket requests. It is worth noting that not all proxy servers support HTTPS and WebSocket requests.

--proxy-bypass-list=hosts

Instruct Electron bypass the proxy server for the given : This switch is only --proxy server when used with 060c0c96b30f7a.

E.g:

app.commandLine.appendSwitch('proxy-bypass-list', '<local>;*.google.com;*foo.com;1.2.3.4:5678')

In the above code, in addition to a local address ( localhost , 127.0.0.1 etc), google.com subdomain to foo.com host address ending hosts , and all 1.2.3.4:5678 other than the address, will be for all hosts proxy server host.

--proxy-pac-url=url

This switch is used to specify the url use on PAC script.

--no-proxy-server

Do not use proxy services and always use direct connections, ignoring all reasonable proxy flags.

--host-rules=rules

A comma-separated list of rule to control how hostnames are mapped.

E.g:

  • MAP * 127.0.0.1 forces all hostnames to map to 127.0.0.1 .
  • MAP *.9xkd.com proxy forces all 9xkd.com subdomains to use "proxy".
  • MAP test.com [::1]:77 forces "test.com" to use an IPv6 loopback address, and also forces port 77 .
  • MAP * jswui, EXCLUDE www.9xkd.com remapped to "jswui", except for "www.9xkd.com".

These mappings are suitable for terminal network requests ( TCP connection and host resolution are connected directly, and CONNECT is connected as a proxy, and terminal host connected with SOCKS proxy).

--host-resolver-rules=rules

This switch is similar to --host-rules , but rules only suitable for host resolution.

--ignore-certificate-errors

This switch is used to ignore certificate-related errors.

--ppapi-flash-path=path

This switch is Pepper Flash path plug path .

--ppapi-flash-version=version

This switch is used to set version attribute (that is, the version number) of the Pepper Flash plug-in.

--log-net-log=path

This switch is used to enable network log events that need to be saved and write them to the path path.

--disable-renderer-backgrounding

This switch is used to prevent Chromium lowering the priority of the hidden rendering process. This flag is globally effective for all rendering processes. If we only want to disable throttling protection for one window, we can take playing silent audio .

--enable-logging

This switch is used to print Chromium information to the console.

app.commandLine.appendSwitch before the user application is loaded, this switch will be effective, but you can set the ELECTRON_ENABLE_LOGGING environment variable to achieve the same effect.

--v=log_level

This switch is used to set the default maximum active V-logging standard, and the default is 0 . Usually the standard value of V-logging

Note that this switch is only valid when --enable-logging turned on.

--vmodule=pattern

Given the maximum V-logging for each module, overwrite the value set by --v For example, my_module=2,foo*=3 will change the log level of the code of my_module.* and foo*.*

Any pattern containing forward or back slashes will be tested against the entire pathname, not just the module. For example, */foo/bar/*=2 will change the log level of all codes in the source files in the foo/bar

This switch only works when --enable-logging is also passed:

--enable-logging

知否
221 声望177 粉丝

Skrike while the iron is hot.