@puppeteer/browsers
从 CLI 或以编程方式管理和启动浏览器/驱动程序。
CLI
使用 npx
运行 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 所需的所有文档。
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
的版本
# 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
命令
npx @puppeteer/browsers clear
要列出所有已安装的浏览器,请使用 list
命令
npx @puppeteer/browsers list
一些示例可以了解 CLI 的外观(有关更多示例,请使用 --help
命令)
# 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
已知限制
- 只有 Chrome/Chromium 才能启动系统浏览器。
API
编程 API 允许从您的代码安装和启动浏览器。有关如何使用 install
、canInstall
、launch
、computeExecutablePath
、computeSystemExecutablePath
和其他方法的示例,请参阅 test
文件夹。
类
类 | 描述 |
---|---|
CLI | |
InstalledBrowser | 备注 此类的构造函数标记为内部的。第三方代码不应直接调用构造函数或创建扩展 |
进程 | |
TimeoutError | 备注 此类的构造函数标记为内部的。第三方代码不应直接调用构造函数或创建扩展 |
枚举
枚举 | 描述 |
---|---|
Browser | 支持的浏览器。 |
BrowserPlatform | 用于以与浏览器下载相关的方式识别 OS 平台 x 架构组合的平台名称。 |
ChromeReleaseChannel |
函数
函数 | 描述 |
---|---|
canDownload(options) | |
computeExecutablePath(options) | |
computeSystemExecutablePath(options) | |
createProfile(browser, opts) | |
detectBrowserPlatform() | |
getInstalledBrowsers(options) | 返回有关缓存目录中安装的浏览器的元数据。 |
getVersionComparator(browser) | 返回给定浏览器的版本比较器,可用于对浏览器版本进行排序。 |
install(options) | 根据 InstallOptions 下载并解压浏览器存档。 |
install(options) | 根据 InstallOptions 下载浏览器存档,但不进行解压。 |
launch(opts) | 根据 LaunchOptions 启动浏览器进程。 |
makeProgressCallback(browser, buildId) | |
resolveBuildId(browser, platform, tag) | |
uninstall(options) |
接口
接口 | 描述 |
---|---|
GetInstalledBrowsersOptions | |
InstallOptions | |
LaunchOptions | |
Options | |
ProfileOptions | |
SystemOptions | |
UninstallOptions |
变量
变量 | 描述 |
---|---|
CDP_WEBSOCKET_ENDPOINT_REGEX | |
WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX |