When to Use
Use this skill for real browser tasks: JS-rendered pages, multi-step forms, screenshots or PDFs, UI debugging, Playwright test authoring, MCP-driven browser control, and structured extraction from rendered pages.
Prefer it when static fetch is insufficient or when the task depends on browser events, visible DOM state, authentication context, uploads or downloads, or user-facing rendering.
If the user mainly wants the agent to drive a browser with simple actions like navigate, click, fill, screenshot, download, or extract, treat MCP as a first-class path.
Use direct Playwright for scripts and tests. Use MCP when browser tools are already in the loop, the user explicitly wants MCP, or the fastest path is browser actions rather than writing new automation code.
Primary fit is repo-owned browser work: tests, debugging, repros, screenshots, and deterministic automation. Treat rendered-page extraction as a secondary use case, not the default identity.
Architecture
This skill is instruction-only. It does not create local memory, setup folders, or persistent profiles by default.
Load only the smallest reference file needed for the task. Keep auth state temporary unless the repository already standardizes it and the user explicitly wants browser-session reuse.
Quick Start
MCP browser path
CODEBLOCK0
Use this path when the agent already has browser tools available or the user wants browser automation without writing new Playwright code.
Common MCP actions
Typical Playwright MCP tool actions include:
- -
browser_navigate for opening a page - INLINECODE1 and
browser_press for interaction - INLINECODE3 and
browser_select_option for forms - INLINECODE5 and
browser_evaluate for inspection and extraction - INLINECODE7 for uploads
- screenshot, PDF, trace, and download capture through the active browser workflow
Common browser outcomes
| Goal | Typical MCP-style action |
|---|
| Open and inspect a site | navigate, wait, inspect, screenshot |
| Complete a form |
navigate, click, fill, select, submit |
| Capture evidence | screenshot, PDF, download, trace |
| Pull structured page data | navigate, wait for rendered state, extract |
| Reproduce a UI bug | headed run, trace, console or network inspection |
Existing test suite
CODEBLOCK1
Bootstrap selectors and flows
CODEBLOCK2
Direct script path
CODEBLOCK3
Quick Reference
| Topic | File |
|---|
| Selector strategy and frame handling | INLINECODE8 |
| Failure analysis, traces, logs, and headed runs |
debugging.md |
| Test architecture, mocks, auth, and assertions |
testing.md |
| CI defaults, retries, workers, and failure artifacts |
ci-cd.md |
| Rendered-page extraction, pagination, and respectful throttling |
scraping.md |
Approach Selection
| Situation | Best path | Why |
|---|
| Static HTML or a simple HTTP response is enough | Use a cheaper fetch path first | Faster, cheaper, less brittle |
| You need a reliable first draft of selectors or flows |
Start with
codegen or a headed exploratory run | Faster than guessing selectors from source or stale DOM |
| Local app, staging app, or repo-owned E2E suite | Use
@playwright/test | Best fit for repeatable tests and assertions |
| One-off browser automation, screenshots, downloads, or rendered extraction | Use direct Playwright API | Simple, explicit, and easy to debug in code |
| Agent/browser-tool workflow already depends on
browser_* tools or the user wants no-code browser control | Use Playwright MCP | Fastest path for navigate-click-fill-screenshot workflows |
| CI failures, flake, or environment drift | Start with
debugging.md and
ci-cd.md | Traces and artifacts matter more than new code |
Core Rules
1. Test user-visible behavior and the real browser boundary
- - Do not spend Playwright on implementation details that unit or API tests can cover more cheaply.
- Use Playwright when success depends on rendered UI, actionability, auth, uploads or downloads, navigation, or browser-only behavior.
2. Make runs isolated before making them clever
- - Keep tests and scripts independent so retries, parallelism, and reruns do not inherit hidden state.
- Extend the repository's existing Playwright harness, config, and fixtures before inventing a parallel testing shape from scratch.
- Do not share mutable accounts, browser state, or server-side data across parallel runs unless the suite was explicitly designed for it.
3. Reconnaissance before action
- - Open, wait, and inspect the rendered state before locking selectors or assertions.
- Use
codegen, headed mode, or traces to discover stable locators instead of guessing from source or stale DOM. - For flaky or CI-only failures, capture a trace before rewriting selectors or waits.
4. Prefer resilient locators and web-first assertions
- - Use role, label, text, alt text, title, or test ID before CSS or XPath.
- Assert the user-visible outcome with Playwright assertions instead of checking only that a click or fill command executed.
- If a locator is ambiguous, disambiguate it. Do not silence strictness with
first(), last(), or nth() unless position is the actual behavior under test.
5. Wait on actionability and app state, not arbitrary time
- - Let Playwright's actionability checks work for you before reaching for sleeps or forced actions.
- Prefer
expect, URL waits, response waits, and explicit app-ready signals over generic timing guesses.
6. Control what you do not own
- - Mock or isolate third-party services, flaky upstream APIs, analytics noise, and cross-origin dependencies whenever the goal is to verify your app.
- For rendered extraction, prefer documented APIs or plain HTTP paths before driving a full browser.
- Do not make live third-party widgets or upstream integrations the reason your suite flakes unless that exact integration is what the user asked to validate.
7. Keep auth, production access, and persistence explicit
- - Do not persist saved browser state by default.
- Reuse auth state only when the repository already standardizes it or the user explicitly asks for session reuse.
- For destructive, financial, medical, production, or otherwise high-stakes flows, prefer staging or local environments and require explicit user confirmation before continuing.
Playwright Traps
- - Guessing selectors from source or using
first(), last(), or nth() to silence ambiguity -> the automation works once and then flakes. - Starting a new Playwright structure when the repo already has config, fixtures, auth setup, or conventions -> the new flow fights the existing harness and wastes time.
- Testing internal implementation details instead of visible outcomes -> the suite passes while the user path is still broken.
- Sharing one authenticated state across parallel tests that mutate server-side data -> failures become order-dependent and hard to trust.
- Reaching for
force: true before understanding overlays, disabled state, or actionability -> the test hides a real bug. - Waiting on
networkidle for chatty SPAs -> analytics, polling, or sockets keep the page "busy" even when the UI is ready. - Driving a full browser when HTTP or an API would answer the question -> more cost, more flake, less signal.
- Treating third-party widgets and live upstream services as if they were stable parts of your own product -> failures stop being actionable.
External Endpoints
| Endpoint | Data Sent | Purpose |
|---|
| User-requested web origins | Browser requests, form input, cookies, uploads, and page interactions required by the task | Automation, testing, screenshots, PDFs, and rendered extraction |
| INLINECODE28 |
Package metadata and tarballs during optional installation | Install Playwright or Playwright MCP |
No other data is sent externally.
Security & Privacy
Data that leaves your machine:
- - Requests sent to the websites the user asked to automate.
- Optional package-install traffic to npm when installing Playwright tooling.
Data that stays local:
- - Source code, traces, screenshots, videos, PDFs, and temporary browser state kept in the workspace or system temp directory.
This skill does NOT:
- - Create hidden memory files or local folder systems.
- Recommend browser-fingerprint hacks, challenge-solving services, or rotating exits.
- Persist sessions or credentials by default.
- Make undeclared network requests beyond the target sites involved in the task and optional tool installation.
- Treat high-stakes production flows as safe to automate without explicit user direction.
Trust
By using this skill, browser requests go to the websites you automate and optional package downloads go through npm.
Only install if you trust those services and the sites involved in your workflow.
Related Skills
Install with
clawhub install <slug> if user confirms:
- -
web - HTTP-first investigation before escalating to a real browser. - INLINECODE31 - Broader extraction workflows when browser automation is not the main challenge.
- INLINECODE32 - Capture and polish visual artifacts after browser work.
- INLINECODE33 - Find and shortlist target pages before automating them.
Feedback
- - If useful: INLINECODE34
- Stay updated: INLINECODE35
何时使用
在需要处理真实浏览器任务时使用此技能:JS渲染页面、多步骤表单、截图或PDF、UI调试、Playwright测试编写、MCP驱动的浏览器控制,以及从渲染页面中结构化提取数据。
当静态获取不足,或任务依赖于浏览器事件、可见DOM状态、认证上下文、上传或下载、面向用户的渲染时,优先使用此技能。
如果用户主要希望代理通过简单的操作(如导航、点击、填写、截图、下载或提取)来驱动浏览器,则将MCP视为首选路径。
对于脚本和测试,直接使用Playwright。当浏览器工具已在工作流程中、用户明确要求使用MCP,或最快路径是浏览器操作而非编写新的自动化代码时,使用MCP。
主要适用场景是仓库自有的浏览器工作:测试、调试、复现、截图和确定性自动化。将渲染页面提取视为次要用例,而非默认定位。
架构
此技能仅为指令式。默认情况下,它不会创建本地内存、设置文件夹或持久化配置文件。
仅加载任务所需的最小参考文件。保持认证状态为临时性,除非仓库已标准化该状态且用户明确希望重用浏览器会话。
快速开始
MCP浏览器路径
bash
npx @playwright/mcp --headless
当代理已有可用的浏览器工具,或用户希望无需编写新的Playwright代码即可实现浏览器自动化时,使用此路径。
常见MCP操作
典型的Playwright MCP工具操作包括:
- - browsernavigate 用于打开页面
- browserclick 和 browserpress 用于交互
- browsertype 和 browserselectoption 用于表单
- browsersnapshot 和 browserevaluate 用于检查和提取
- browserchoosefile 用于上传
- 通过活动浏览器工作流程进行截图、PDF、追踪和下载捕获
常见浏览器结果
| 目标 | 典型MCP风格操作 |
|---|
| 打开并检查网站 | 导航、等待、检查、截图 |
| 完成表单 |
导航、点击、填写、选择、提交 |
| 捕获证据 | 截图、PDF、下载、追踪 |
| 提取结构化页面数据 | 导航、等待渲染状态、提取 |
| 复现UI错误 | 有头运行、追踪、控制台或网络检查 |
现有测试套件
bash
npx playwright test
npx playwright test --headed
npx playwright test --trace on
引导选择器和流程
bash
npx playwright codegen https://example.com
直接脚本路径
javascript
const { chromium } = require(playwright);
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(https://example.com);
await page.screenshot({ path: page.png, fullPage: true });
await browser.close();
})();
快速参考
| 主题 | 文件 |
|---|
| 选择器策略和框架处理 | selectors.md |
| 失败分析、追踪、日志和有头运行 |
debugging.md |
| 测试架构、模拟、认证和断言 | testing.md |
| CI默认设置、重试、工作进程和失败产物 | ci-cd.md |
| 渲染页面提取、分页和合理的限流 | scraping.md |
方法选择
| 情况 | 最佳路径 | 原因 |
|---|
| 静态HTML或简单的HTTP响应已足够 | 首先使用更便宜的获取路径 | 更快、更便宜、更不易出错 |
| 需要可靠的选择器或流程初稿 |
从codegen或有头探索性运行开始 | 比从源代码或过时DOM猜测选择器更快 |
| 本地应用、预发布应用或仓库自有的E2E套件 | 使用@playwright/test | 最适合可重复的测试和断言 |
| 一次性浏览器自动化、截图、下载或渲染提取 | 直接使用Playwright API | 简单、明确、易于在代码中调试 |
| 代理/浏览器工具工作流程已依赖browser_*工具,或用户希望无代码浏览器控制 | 使用Playwright MCP | 导航-点击-填写-截图工作流程的最快路径 |
| CI失败、不稳定或环境漂移 | 从debugging.md和ci-cd.md开始 | 追踪和产物比新代码更重要 |
核心规则
1. 测试用户可见行为和真实的浏览器边界
- - 不要将Playwright用于单元测试或API测试可以更便宜覆盖的实现细节。
- 当成功取决于渲染UI、可操作性、认证、上传或下载、导航或仅浏览器行为时,使用Playwright。
2. 先让运行隔离,再让运行智能
- - 保持测试和脚本独立,以便重试、并行和重新运行不会继承隐藏状态。
- 在从头发明并行测试结构之前,先扩展仓库现有的Playwright工具、配置和夹具。
- 除非套件明确设计为共享,否则不要在并行运行之间共享可变账户、浏览器状态或服务器端数据。
3. 行动前先侦察
- - 在锁定选择器或断言之前,先打开、等待并检查渲染状态。
- 使用codegen、有头模式或追踪来发现稳定的定位器,而不是从源代码或过时DOM猜测。
- 对于不稳定或仅CI失败的测试,在重写选择器或等待之前先捕获追踪。
4. 优先使用弹性定位器和Web优先断言
- - 在CSS或XPath之前,优先使用角色、标签、文本、替代文本、标题或测试ID。
- 使用Playwright断言来断言用户可见的结果,而不是仅检查点击或填写命令是否执行。
- 如果定位器有歧义,请消除歧义。不要使用first()、last()或nth()来压制严格性,除非位置是实际测试的行为。
5. 等待可操作性和应用状态,而非任意时间
- - 在诉诸休眠或强制操作之前,让Playwright的可操作性检查为您工作。
- 优先使用expect、URL等待、响应等待和明确的应用就绪信号,而非通用的时间猜测。
6. 控制你不拥有的内容
- - 当目标是验证您的应用时,模拟或隔离第三方服务、不稳定的上游API、分析噪音和跨源依赖。
- 对于渲染提取,在驱动完整浏览器之前,优先使用文档化的API或普通HTTP路径。
- 不要让实时第三方小部件或上游集成成为套件不稳定的原因,除非用户要求验证的正是该集成。
7. 明确处理认证、生产访问和持久化
- - 默认情况下不要持久化保存的浏览器状态。
- 仅当仓库已标准化认证状态或用户明确要求会话重用时,才重用认证状态。
- 对于破坏性、金融、医疗、生产或其他高风险流程,优先使用预发布或本地环境,并在继续之前要求用户明确确认。
Playwright陷阱
- - 从源代码猜测选择器,或使用first()、last()或nth()来压制歧义 -> 自动化一次成功,然后变得不稳定。
- 当仓库已有配置、夹具、认证设置或约定时,启动新的Playwright结构 -> 新流程与现有工具冲突并浪费时间。
- 测试内部实现细节而非可见结果 -> 套件通过,但用户路径仍然损坏。
- 在并行测试之间共享一个认证状态,而这些测试会改变服务器端数据 -> 失败变得依赖于顺序且难以信任。
- 在理解覆盖层、禁用状态或可操作性之前使用force: true -> 测试隐藏了真正的错误。
- 为聊天型SPA等待networkidle -> 分析、轮询或套接字使页面保持忙碌状态,即使UI已就绪。
- 当HTTP或API可以回答问题时就驱动完整浏览器 -> 更多成本、更多不稳定、更少信号。
- 将第三方小部件和实时上游服务视为您自己产品的稳定部分 -> 失败变得不可操作。
外部端点
| 端点 | 发送的数据 | 目的 |
|---|
| 用户请求的Web源 | 任务所需的浏览器请求、表单输入、cookies、上传和页面交互 | 自动化、测试、截图、PDF和渲染提取 |
| https://registry.npmjs.org |
可选安装期间的包元数据和压缩包 | 安装Playwright或Playwright MCP |
没有其他数据被发送到外部。
安全与隐私
离开您机器的数据:
- - 发送到用户要求自动化的网站的请求。
- 安装Playwright工具时发送到npm的可选包安装流量。
留在本地的数据:
- - 源代码、追踪、截图、视频、PDF和保存在工作区或系统临时目录中的临时浏览器状态。
此技能不会:
- - 创建隐藏的内存文件或本地文件夹系统。
- 推荐浏览器指纹破解、挑战解决服务或轮换出口。
- 默认持久化会话或凭据。
- 在任务涉及的目标网站