Skip to main content
Version: 24.38.0

ConnectOptions 接口

🌐 ConnectOptions interface

启动任何浏览器或连接到现有浏览器实例时可以传递的通用浏览器选项。

🌐 Generic browser options that can be passed when launching any browser or when connecting to an existing browser instance.

语法

🌐 Signature

export interface ConnectOptions

属性

🌐 Properties

属性

🌐 Property

修饰符

🌐 Modifiers

类型

🌐 Type

描述

🌐 Description

默认

🌐 Default

acceptInsecureCerts

optional

boolean

导航期间是否忽略 HTTPS 错误。

🌐 Whether to ignore HTTPS errors during navigation.

false

browserURL

optional

string

browserWSEndpoint

optional

string

capabilities

optional

支持的 WebDriver 功能

WebDriver BiDi 功能已传递给 BiDi session.new

🌐 WebDriver BiDi capabilities passed to BiDi session.new.

附注

仅适用于 protocol="webDriverBiDi"Puppeteer.connect()

🌐 Only works for protocol="webDriverBiDi" and Puppeteer.connect().

channel

optional

ChromeReleaseChannel

(实验性) 如果指定,Puppeteer 会在指定渠道的已知默认用户数据目录中查找打开的 WebSocket,并尝试使用 ws://localhost:$ActivePort/devtools/browser 连接它。仅适用于 Chrome 并在 Node.js 中运行时有效。

此选项与 puppeteer.connect() 一起使用时为实验性功能。

🌐 This option is experimental when used with puppeteer.connect().

defaultViewport

optional

[视窗](./puppeteer.viewport.md) |无效

设置每个页面的视口。

🌐 Sets the viewport for each page.

'{width: 800, height: 600}'

downloadBehavior

optional

下载行为

设置上下文的下载行为。

🌐 Sets the download behavior for the context.

handleDevToolsAsPage

optional

boolean

是否将 DevTools 窗口作为 Puppeteer 中的页面处理。仅在支持 CDP 的 Chrome 中可用。

🌐 Whether to handle the DevTools windows as pages in Puppeteer. Supported only in Chrome with CDP.

'false'

headers

optional

Record<string, string>

用于 Web 套接字连接的标头。

🌐 Headers to use for the web socket connection.

附注

仅适用于 Node.js 环境。

🌐 Only works in the Node.js environment.

networkEnabled

optional

boolean

(实验性) 实验性设置,用于默认禁用监控网络事件。设置为 false 时,依赖网络事件的 Puppeteer 部分功能将无法正常工作,例如 HTTPRequest 和 HTTPResponse。

true

protocol

optional

协议类型

在运行时确定:

🌐 Determined at run time:

  • 启动 Chrome - 'cdp'。
  • 启动 Firefox - 'webDriverBiDi'。
  • 连接到浏览器 - 'cdp'。
protocolTimeout

optional

number

单独协议 (CDP) 调用的超时设置。

🌐 Timeout setting for individual protocol (CDP) calls.

180_000

slowMo

optional

number

将 Puppeteer 操作减慢指定的毫秒数以帮助调试。

🌐 Slows down Puppeteer operations by the specified amount of milliseconds to aid debugging.

targetFilter

optional

TargetFilterCallback

用于决定 Puppeteer 是否应连接到给定目标的回调。

🌐 Callback to decide if Puppeteer should connect to a given target or not.

transport

optional

连接传输