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 |
| boolean | 导航期间是否忽略 HTTPS 错误。 🌐 Whether to ignore HTTPS errors during navigation. |
|
| allowlist |
| string[] | (实验) 允许的 URL 模式列表。 需要 Chrome 149 以上版本。 此选项允许你限制浏览器访问任何 URL,除了与 allowList 中的模式匹配的 URL。它使用标准的 [URLPattern](https://urlpattern.spec.whatwg.org/) API 来匹配 URL。 🌐 This option allows you to restrict the browser from accessing any URLs except for those that match the patterns in the allowList. It uses the standard [URLPattern](https://urlpattern.spec.whatwg.org/) API to match URLs. 当连接到现有浏览器时,Puppeteer 将默默地从任何已打开且违反模式的目标中分离。 🌐 When connecting to an existing browser, Puppeteer will silently detach from any already open targets that violate the patterns. 对于浏览器发出的任何网络请求(包括导航和像图片或脚本这样的子资源),如果 URL 与允许列表中的任何模式不匹配,请求将会失败并出现错误。 🌐 For any network requests made by the browser (including navigations and subresources like images or scripts), the request will fail with an error if the URL does not match any pattern in the allowlist. 附注 当前仅支持 Chrome。 🌐 Currently only supported for Chrome. 该功能在 Puppeteer 附加到 CDP 目标时可用。它会拦截 Chrome 中网络服务的请求。Chrome 可能会以其他方式执行一些网络访问,或者某些网页功能可能会绕过网络服务。该功能旨在作为在 Puppeteer 控制下基于 LLM 使用的额外防护措施,而不是完整的网络沙箱。对于完整的网络沙箱,我们建议使用容器/操作系统级别的沙箱机制。 🌐 The feature works while Puppeteer is attached to the CDP targets. It intercepts requests in the network service in Chrome. Chrome may perform some network access in other ways or some web features may omit the network service. The feature is meant as an additional guardrails to LLM-based usage under Puppeteer control and not a complete network sandbox. For complete network sandboxing, we recommend using container/OS-level sandbox mechanism. 不能与 ConnectOptions.blocklist 一起使用。 🌐 Cannot be used along with ConnectOptions.blocklist. | |
| blocklist |
| string[] | (实验性) 要阻止的 URL 模式列表。 这个选项可以限制浏览器访问特定的 URL 或来源。它使用标准的 [URLPattern](https://urlpattern.spec.whatwg.org/) API 来匹配 URL。 🌐 This option allows you to restrict the browser from accessing specific URLs or origins. It uses the standard [URLPattern](https://urlpattern.spec.whatwg.org/) API to match URLs. 当连接到现有浏览器时,Puppeteer 将默默地从任何已打开且违反模式的目标中分离。 🌐 When connecting to an existing browser, Puppeteer will silently detach from any already open targets that violate the patterns. 对于浏览器发出的任何网络请求(包括导航和像图片或脚本这样的子资源),如果 URL 与被阻止的模式匹配,请求将失败并返回错误。 🌐 For any network requests made by the browser (including navigations and subresources like images or scripts), the request will fail with an error if the URL matches a blocked pattern. 附注 当前仅支持 Chrome。 🌐 Currently only supported for Chrome. 该功能在 Puppeteer 附加到 CDP 目标时可用。它会拦截 Chrome 中网络服务的请求。Chrome 可能会以其他方式执行一些网络访问,或者某些网页功能可能会绕过网络服务。该功能旨在作为在 Puppeteer 控制下基于 LLM 使用的额外防护措施,而不是完整的网络沙箱。对于完整的网络沙箱,我们建议使用容器/操作系统级别的沙箱机制。 🌐 The feature works while Puppeteer is attached to the CDP targets. It intercepts requests in the network service in Chrome. Chrome may perform some network access in other ways or some web features may omit the network service. The feature is meant as an additional guardrails to LLM-based usage under Puppeteer control and not a complete network sandbox. For complete network sandboxing, we recommend using container/OS-level sandbox mechanism. 不能与 ConnectOptions.allowlist 一起使用。 🌐 Cannot be used along with ConnectOptions.allowlist. | |
| browserURL |
| string | ||
| browserWSEndpoint |
| string | ||
| capabilities |
| WebDriver BiDi 功能已传递给 BiDi 🌐 WebDriver BiDi capabilities passed to BiDi 附注 仅适用于 🌐 Only works for | ||
| channel |
| (实验性) 如果指定,Puppeteer 会在指定渠道的已知默认用户数据目录中查找打开的 WebSocket,并尝试使用 ws://localhost:$ActivePort/devtools/browser 连接它。仅适用于 Chrome 并在 Node.js 中运行时有效。 此选项与 puppeteer.connect() 一起使用时为实验性功能。 🌐 This option is experimental when used with puppeteer.connect(). | ||
| defaultViewport |
| [视窗](./puppeteer.viewport.md) |无效 | 设置每个页面的视口。 🌐 Sets the viewport for each page. | '{width: 800, height: 600}' |
| downloadBehavior |
| 设置上下文的下载行为。 🌐 Sets the download behavior for the context. | ||
| handleDevToolsAsPage |
| boolean | 是否将 DevTools 窗口作为 Puppeteer 中的页面处理。仅在支持 CDP 的 Chrome 中可用。 🌐 Whether to handle the DevTools windows as pages in Puppeteer. Supported only in Chrome with CDP. | 'false' |
| headers |
| Record<string, string> | 用于 Web 套接字连接的标头。 🌐 Headers to use for the web socket connection. 附注 仅适用于 Node.js 环境。 🌐 Only works in the Node.js environment. | |
| issuesEnabled |
| boolean | (实验性) 实验性设置,用于默认禁用监控问题事件。 |
|
| networkEnabled |
| boolean | (实验性) 实验性设置,用于默认禁用监控网络事件。设置为 |
|
| protocol |
| 在运行时确定: 🌐 Determined at run time:
| ||
| protocolTimeout |
| number | 单独协议 (CDP) 调用的超时设置。 🌐 Timeout setting for individual protocol (CDP) calls. |
|
| slowMo |
| number | 将 Puppeteer 操作减慢指定的毫秒数以帮助调试。 🌐 Slows down Puppeteer operations by the specified amount of milliseconds to aid debugging. | |
| targetFilter |
| 用于决定 Puppeteer 是否应连接到给定目标的回调。 🌐 Callback to decide if Puppeteer should connect to a given target or not. | ||
| transport |
|