Skip to main content

安装

🌐 Installation

先决条件

🌐 Prerequisites

  • Node.js 20 或更新版本
  • 一个编码代理:Claude Code、GitHub Copilot 或类似工具

全球安装

🌐 Global installation

npm install -g @playwright/cli@latest
playwright-cli --help

使用你项目里的版本

🌐 Using the version in your project

如果 Playwright 已经是项目的依赖,那么可以通过它使用 CLI —— 不需要全局安装:

🌐 If Playwright is already a dependency of the project, the CLI is available through it — no global install needed:

npx --no-install playwright --version # check that a local Playwright exists
npx playwright cli --help

到处这些文档都写着 playwright-cli <command>npx playwright cli <command> 的用法也一样。

🌐 Everywhere these docs write playwright-cli <command>, npx playwright cli <command> works the same way.

正在初始化工作区

🌐 Initializing a workspace

playwright-cli install

这会在当前工作目录下创建一个 .playwright 目录,将其添加到 .gitignore,并在缺少的情况下下载配置好的浏览器。

🌐 This creates a .playwright directory in the current working directory, adds it to .gitignore, and downloads the configured browser if it is missing.

安装技能

🌐 Installing skills

像 Claude Code 和 GitHub Copilot 这样的编码助手使用本地安装的技能来获取关于可用命令和工作流程的更丰富的上下文:

🌐 Coding agents like Claude Code and GitHub Copilot use locally installed skills for richer context about available commands and workflows:

playwright-cli install --skills # same as --skills=claude
playwright-cli install --skills=claude # .claude/skills/playwright-cli
playwright-cli install --skills=agents # .agents/skills/playwright-cli
playwright-cli install --skills -g # install into the home directory

--global(别名 -g)将技能安装到 ~/.claude/skills~/.agents/skills 中,这样它在每个项目中都可以使用。它需要 --skills 并且会跳过工作区初始化。

查看技能了解技能包含的内容。

🌐 See Skills for what the skill contains.

安装浏览器

🌐 Installing browsers

CLI 在首次使用时会自动下载浏览器。要显式安装,请执行:

🌐 The CLI downloads a browser automatically on first use. To install explicitly:

playwright-cli install-browser # install the browsers this version needs
playwright-cli install-browser firefox # install one specific browser
playwright-cli install-browser --with-deps # install with system dependencies

安装选项

🌐 Install options

标志描述
--with-deps安装系统依赖(Linux)
--dry-run预览将要安装的内容
--list列出所有安装中可用的浏览器
--force即使已存在也强制重新安装
--only-shell仅安装 Chromium 无头模式
--no-shell跳过 Chromium 无头模式

无需技能操作

🌐 Skills-less operation

你也可以直接将你的代理指向 CLI,让它自行发现命令:

🌐 You can also point your agent at the CLI directly and let it discover commands on its own:

Test the "add todo" flow on https://demo.playwright.dev/todomvc using playwright-cli.
Check playwright-cli --help for available commands.

环境设置

🌐 Environment setup

配置你的编码代理以使用特定的会话:

🌐 Configure your coding agent to use a specific session:

PLAYWRIGHT_CLI_SESSION=todo-app claude .

下一步

🌐 Next steps

  • 快速开始 — 试试命令行操作
  • 快照 — 元素引用的工作原理
  • 命令参考 — 每个命令,分类整理
  • 配置 — 无头模式,浏览器选择,配置文件