@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 | 備註 此類別的建構函式標記為內部使用。第三方程式碼不應直接呼叫建構函式或建立擴充 |
Process | |
TimeoutError | 備註 此類別的建構函式標記為內部使用。第三方程式碼不應直接呼叫建構函式或建立擴充 |
列舉
列舉 | 描述 |
---|---|
Browser | 支援的瀏覽器。 |
BrowserPlatform | 用於識別作業系統平台 x 架構組合的平台名稱,其方式與瀏覽器下載相關。 |
ChromeReleaseChannel |
函式
介面
介面 | 描述 |
---|---|
GetInstalledBrowsersOptions | |
InstallOptions | |
LaunchOptions | |
Options | |
ProfileOptions | |
SystemOptions | |
UninstallOptions |
變數
變數 | 描述 |
---|---|
CDP_WEBSOCKET_ENDPOINT_REGEX | |
WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX |