Skip to main content
Version: 22.14.0

@puppeteer/browsers

从 CLI 或以编程方式管理和启动浏览器/驱动程序。

¥Manage and launch browsers/drivers from a CLI or programmatically.

CLI

使用 npx 运行 CLI:

¥Use npx to run the CLI:

npx @puppeteer/browsers --help

内置的每命令 help 将提供使用 CLI 所需的所有文档。

¥Built-in per-command help will provide all documentation you need to use the CLI.

npx @puppeteer/browsers --help # help for all commands
npx @puppeteer/browsers install --help # help for the install command
npx @puppeteer/browsers launch --help # help for the launch command

通过一些示例来了解 CLI 的外观(使用 --help 命令获取更多示例):

¥Some example to give an idea of what the CLI looks like (use the --help command for more examples):

# Download the latest available Chrome for Testing binary corresponding to the Stable channel.
npx @puppeteer/browsers install chrome@stable

# Download a specific Chrome for Testing version.
npx @puppeteer/browsers install chrome@116.0.5793.0

# Download the latest Chrome for Testing version for the given milestone.
npx @puppeteer/browsers install chrome@117

# Download the latest available ChromeDriver version corresponding to the Canary channel.
npx @puppeteer/browsers install chromedriver@canary

# Download a specific ChromeDriver version.
npx @puppeteer/browsers install chromedriver@116.0.5793.0

已知的限制

¥Known limitations

  1. 仅适用于 Chrome/Chromium 启动系统浏览器。

    ¥Launching the system browsers is only possible for Chrome/Chromium.

API

编程 API 允许从你的代码安装和启动浏览器。有关如何使用 installcanInstalllaunchcomputeExecutablePathcomputeSystemExecutablePath 等方法的示例,请参阅 test 文件夹。

¥The programmatic API allows installing and launching browsers from your code. See the test folder for examples on how to use the install, canInstall, launch, computeExecutablePath, computeSystemExecutablePath and other methods.

¥Classes

描述

CLI
InstalledBrowser

评论:

此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 InstalledBrowser 类的子类。

Process
TimeoutError

评论:

此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 TimeoutError 类的子类。

枚举

¥Enumerations

枚举

描述

Browser

支持的浏览器。

BrowserPlatform

平台名称用于以与浏览器下载相关的方式标识操作系统平台 x 架构组合。

ChromeReleaseChannel

函数

¥Functions

函数

描述

canDownload(options)
computeExecutablePath(options)
computeSystemExecutablePath(options)
createProfile(browser, opts)
detectBrowserPlatform()
getInstalledBrowsers(options)

返回有关安装在缓存目录中的浏览器的元数据。

getVersionComparator(browser)

返回给定浏览器的版本比较器,可用于对浏览器版本进行排序。

install(options)
install(options)
launch(opts)
makeProgressCallback(browser, buildId)
resolveBuildId(browser, platform, tag)
uninstall(options)

接口

¥Interfaces

界面

描述

GetInstalledBrowsersOptions
InstallOptions
LaunchOptions
选项
ProfileOptions
SystemOptions
UninstallOptions

变量

¥Variables

多变的

描述

CDP_WEBSOCKET_ENDPOINT_REGEX
WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX