Skip to main content
Version: 24.38.0

LaunchOptions 接口

🌐 LaunchOptions interface

启动任何浏览器时可以传递的通用启动选项。

🌐 Generic launch options that can be passed when launching any browser.

语法

🌐 Signature

export interface LaunchOptions extends ConnectOptions

扩展自: ConnectOptions

属性

🌐 Properties

属性

🌐 Property

修饰符

🌐 Modifiers

类型

🌐 Type

描述

🌐 Description

默认

🌐 Default

args

optional

string[]

要传递给浏览器实例的其他命令行参数。

🌐 Additional command line arguments to pass to the browser instance.

browser

optional

支持的浏览器

要启动哪个浏览器。

🌐 Which browser to launch.

chrome

channel

optional

ChromeReleaseChannel

如果为 Chrome 指定,则在已知系统位置查找常规 Chrome 安装,而不是使用打包的 Chrome 二进制文件。

🌐 If specified for Chrome, looks for a regular Chrome installation at a known system location instead of using the bundled Chrome binary.

debuggingPort

optional

number

指定要使用的调试端口号

🌐 Specify the debugging port number to use

devtools

optional

boolean

是否为每个标签自动打开 DevTools 面板。如果设置为 true,则 headless 将被强制为 false

🌐 Whether to auto-open a DevTools panel for each tab. If this is set to true, then headless will be forced to false.

false

dumpio

optional

boolean

如果为真,将浏览器进程的标准输出和标准错误输出管道到 process.stdoutprocess.stderr

🌐 If true, pipes the browser process stdout and stderr to process.stdout and process.stderr.

false

enableExtensions

optional

布尔值 | 字符串数组

🌐 boolean | string[]

如果 true,则避免向浏览器传递默认参数,这些默认参数会阻止扩展程序被启用。传递字符串列表将会把提供的路径作为未打包的扩展程序加载。

🌐 If true, avoids passing default arguments to the browser that would prevent extensions from being enabled. Passing a list of strings will load the provided paths as unpacked extensions.

env

optional

Record<string, string | undefined>

指定浏览器可见的环境变量。

🌐 Specify environment variables that will be visible to the browser.

process.env 的内容。

🌐 The contents of process.env.

executablePath

optional

string

要使用的浏览器可执行文件的路径,用来替代打包的浏览器。请注意,Puppeteer 仅保证与打包的浏览器一起使用,因此请自行承担使用此设置的风险。

🌐 Path to a browser executable to use instead of the bundled browser. Note that Puppeteer is only guaranteed to work with the bundled browser, so use this setting at your own risk.

附注

使用此功能时,建议设置 browser 属性,因为 Puppeteer 默认会将其设置为 chrome

🌐 When using this is recommended to set the browser property as well as Puppeteer will default to chrome by default.

extraPrefsFirefox

optional

Record<string, unknown>

可以在启动 Firefox 时传递的额外偏好设置

handleSIGHUP

optional

boolean

关闭 SIGHUP 上的浏览器进程。

🌐 Close the browser process on SIGHUP.

true

handleSIGINT

optional

boolean

关闭 Ctrl+C 上的浏览器进程。

🌐 Close the browser process on Ctrl+C.

true

handleSIGTERM

optional

boolean

关闭 SIGTERM 上的浏览器进程。

🌐 Close the browser process on SIGTERM.

true

headless

optional

布尔 |“壳”

🌐 boolean | 'shell'

是否以无头模式运行浏览器。

🌐 Whether to run the browser in headless mode.

附注

  • true新无头 模式下启动浏览器。
  • 'shell' 启动了被称为旧无头模式的 shell

true

ignoreDefaultArgs

optional

布尔值 | 字符串数组

🌐 boolean | string[]

如果 true,在创建浏览器时不要使用 puppeteer.defaultArgs()。如果提供了数组,这些参数将被过滤掉。请谨慎使用——你很可能会想使用 Puppeteer 默认的参数。

🌐 If true, do not use puppeteer.defaultArgs() when creating a browser. If an array is provided, these args will be filtered out. Use this with care - you probably want the default arguments Puppeteer uses.

false

pipe

optional

boolean

通过管道连接到浏览器,而不是通过 WebSocket。仅支持 Chrome。

🌐 Connect to a browser over a pipe instead of a WebSocket. Only supported with Chrome.

false

signal

optional

AbortSignal

如果提供,当信号被中止时,浏览器将被关闭。

🌐 If provided, the browser will be closed when the signal is aborted.

timeout

optional

number

等待浏览器启动的最长时间(毫秒)。传入 0 可禁用超时。

🌐 Maximum time in milliseconds to wait for the browser to start. Pass 0 to disable the timeout.

30_000(30秒)。

userDataDir

optional

string

用户数据目录的路径。更多信息请参见 Chromium 文档

🌐 Path to a user data directory. see the Chromium docs for more info.

waitForInitialPage

optional

boolean

是否等待初始页面准备就绪。当用户明确禁用该选项时很有用(例如 Chrome 的 --no-startup-window)。

🌐 Whether to wait for the initial page to be ready. Useful when a user explicitly disables that (e.g. --no-startup-window for Chrome).

true