@puppeteer/browsers
从 CLI 或以编程方式管理和启动浏览器/驱动程序。
¥Manage and launch browsers/drivers from a CLI or programmatically.
系统要求
¥System requirements
- 
兼容的 Node 版本(参见
package.json中的engines)。¥A compatible Node version (see
enginesinpackage.json). - 
对于 Firefox 下载:
¥For Firefox downloads:
- 
Linux 版本:需要
xz和bzip2实用程序来解压.tar.gz和.tar.bz2档案。¥Linux builds:
xzandbzip2utilities are required to unpack.tar.gzand.tar.bz2archives. - 
MacOS 版本:需要
hdiutil来解压.dmg档案。¥MacOS builds:
hdiutilis required to unpack.dmgarchives. 
 - 
 
CLI
使用 npx 运行 CLI:
¥Use npx to run the CLI:
# This will install and run the @puppeteer/browsers package.
# If it is already installed in the current directory, the installed
# version will be used.
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
npx @puppeteer/browsers clear --help # help for the clear command
npx @puppeteer/browsers list --help # help for the list command
使用 npx 时,你可以指定 @puppeteer/browsers 的版本:
¥You can specify the version of the @puppeteer/browsers when using
npx:
# Always install and use the latest version from the registry.
npx @puppeteer/browsers@latest --help
# Always use a specifc version.
npx @puppeteer/browsers@2.4.1 --help
# Always install the latest version and automatically confirm the installation.
npx --yes @puppeteer/browsers@latest --help
要清除所有已安装的浏览器,请使用 clear 命令:
¥To clear all installed browsers, use the clear command:
npx @puppeteer/browsers clear
要列出所有已安装的浏览器,请使用 list 命令:
¥To list all installed browsers, use the list command:
npx @puppeteer/browsers list
通过一些示例来了解 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
# On Ubuntu/Debian and only for Chrome, install the browser and required system dependencies.
# If the browser version has already been installed, the command
# will still attempt to install system dependencies.
# Requires root privileges.
npx puppeteer browsers install chrome --install-deps
已知的限制
¥Known limitations
- 
仅适用于 Chrome/Chromium 启动系统浏览器。
¥Launching the system browsers is only possible for Chrome/Chromium.
 
API
编程 API 允许从你的代码安装和启动浏览器。有关如何使用 install、canInstall、launch、computeExecutablePath、computeSystemExecutablePath 等方法的示例,请参阅 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 | 评论: 此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展   | 
| Process | |
| TimeoutError | 评论: 此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展   | 
枚举
¥Enumerations
枚举  | 描述  | 
|---|---|
| Browser | 支持的浏览器。  | 
| BrowserPlatform | 平台名称用于以与浏览器下载相关的方式标识操作系统平台 x 架构组合。  | 
| BrowserTag | 描述浏览器发布渠道的枚举。 你可以将其与 resolveBuildId() 结合使用,以根据发布渠道解析构建 ID。  | 
| ChromeReleaseChannel | 
函数
¥Functions
函数  | 描述  | 
|---|---|
| canDownload(options) | |
| computeExecutablePath(options) | |
| computeSystemExecutablePath(options) | 通过检查已知安装位置(使用 https://pptr.nodejs.cn/browsers-api/browsers.computesystemexecutablepath),返回给定发布渠道名称的系统范围 Chrome 安装的路径。如果在预期路径中找不到 Chrome 实例,则会抛出错误。  | 
| createProfile(browser, opts) | |
| detectBrowserPlatform() | |
| getDownloadUrl(browser, platform, buildId, baseUrl) | 检索用于下载指定浏览器二进制存档的 URL。 存档与指定的特定平台和版本 ID 绑定。  | 
| getInstalledBrowsers(options) | 返回有关安装在缓存目录中的浏览器的元数据。  | 
| getVersionComparator(browser) | 返回给定浏览器的版本比较器,可用于对浏览器版本进行排序。  | 
| install(options) | 根据 InstallOptions 下载并解压浏览器存档。  | 
| install(options) | 根据 InstallOptions 下载浏览器存档而不解压。  | 
| launch(opts) | 根据 LaunchOptions 启动浏览器进程。  | 
| makeProgressCallback(browser, buildId) | |
| resolveBuildId(browser, platform, tag) | |
| uninstall(options) | 
接口
¥Interfaces
界面  | 描述  | 
|---|---|
| GetInstalledBrowsersOptions | |
| InstallOptions | |
| LaunchOptions | |
| Metadata_2 | |
| 选项 | |
| ProfileOptions | |
| SystemOptions | |
| UninstallOptions | 
变量
¥Variables
多变的  | 描述  | 
|---|---|
| CDP_WEBSOCKET_ENDPOINT_REGEX | |
| WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX |