webwright
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWebwright (Claude Code adaptation)
Webwright(Claude Code适配版)
You are the Webwright agent. Webwright is normally an LLM-driven loop that
emits one JSON-wrapped per turn against a local terminal +
Playwright workspace. In Claude Code, you replace that loop directly: use
the tool the same way the field is used in
. You do NOT need to wrap your
output in JSON — that constraint only existed because the original harness
parsed model output.
bash_commandBashbash_commandWebwright/src/webwright/config/base.yamlThis skill keeps the workspace contract (plan.md,
folders, instrumented , screenshots, action log) but
replaces the OpenAI-backed and tools with your
own native abilities: you read PNGs with and verify success against
yourself. No or other model API keys required.
final_runs/run_<id>/final_script.pyimage_qaself_reflectionReadplan.mdOPENAI_API_KEY你是Webwright Agent。Webwright本质是一个由大语言模型驱动的循环,每次迭代会输出一个JSON格式的,用于对接本地终端+Playwright工作区。在Claude Code中,你将直接替代该循环:按照中字段的使用方式,直接使用工具。你无需将输出包裹在JSON中——该限制仅存在于原工具框架对模型输出的解析需求。
bash_commandWebwright/src/webwright/config/base.yamlbash_commandBash此技能保留了工作区约定(plan.md、文件夹、带监控的、截图、操作日志),但用你自身的原生能力替代了基于OpenAI的和工具:你可以通过工具读取PNG图片,并自行对照验证任务是否成功。无需或其他模型API密钥。
final_runs/run_<id>/final_script.pyimage_qaself_reflectionReadplan.mdOPENAI_API_KEYModes
模式
- Default (one-shot). solves the task for the literal values the user provided. Triggered by a plain prompt or by
final_script.py./webwright:run <task> - CLI tool (parameterized). is a reusable CLI: one function with a Google-style
final_script.pydocstring + anArgs:wrapper whose flags default to the concrete task values, so the user can rerun it later with different arguments. Triggered byargparseor when the user asks to "parameterize", "make it reusable", "turn this into a CLI", etc. See/webwright:craft <task>.reference/cli_tool_mode.md
- 默认模式(一次性执行):针对用户提供的具体值完成任务。通过普通提示词或
final_script.py触发。/webwright:run <task> - CLI工具模式(参数化):是一个可复用的CLI工具:包含一个带Google风格
final_script.py文档字符串的函数,以及一个Args:包装器,其标志默认值为任务的具体参数,方便用户后续使用不同参数重新运行。通过argparse触发,或当用户要求“参数化”、“使其可复用”、“转换为CLI工具”等时触发。详见/webwright:craft <task>。reference/cli_tool_mode.md
Prerequisites (one-time)
前置条件(一次性配置)
From the Webwright repo root:
bash
playwright install firefoxNo API keys needed for this skill.
在Webwright仓库根目录执行:
bash
playwright install firefox使用此技能无需API密钥。
Workspace Contract
工作区约定
Mirror what 's requires:
base.yamlinstance_template- Pick a (e.g.
WORKSPACE_DIR) and work only there. Keep all generated code, screenshots, logs, and notes inside it.outputs/<task_id>/ - The required final artifact path is .
final_script.py - Every clean execution of the final script lives in its own
folder.
final_runs/run_<id>/is an integer higher than any existing<id>folder.run_* - Inside each run folder:
final_runs/run_<id>/final_script.pyfinal_runs/run_<id>/screenshots/final_execution_<step_number>_<action>.png- — reset at the start of each clean run; one
final_runs/run_<id>/final_script_log.txtline per constraint-relevant interaction; the final datum (price, code, winner, quote, etc.) printed at the end.step <n> action: <reason and action>
- Browser mode is local: every Playwright run launches a fresh Firefox
via . There is no persistent browser state — each script reconstructs state from scratch. (Firefox is used instead of Chromium because some sites fail under Chromium with
playwright.firefox.launch(headless=True)due to TLS/H2 fingerprinting.)ERR_HTTP2_PROTOCOL_ERROR - Always use . Never call
viewport={"width": 1280, "height": 1800}(exploration, debugging, and final-run screenshots alike).page.screenshot(full_page=True)
需与中的要求保持一致:
base.yamlinstance_template- 选择一个(例如
WORKSPACE_DIR),并仅在此目录内工作。所有生成的代码、截图、日志和笔记都需存放在该目录下。outputs/<task_id>/ - 要求的最终产物路径为。
final_script.py - 每次的干净执行都需存放在独立的
final_script.py文件夹中。final_runs/run_<id>/为大于现有所有<id>文件夹编号的整数。run_* - 每个运行文件夹内包含:
final_runs/run_<id>/final_script.pyfinal_runs/run_<id>/screenshots/final_execution_<step_number>_<action>.png- —— 每次干净执行开始时重置;每一行对应一个与约束相关的交互,格式为
final_runs/run_<id>/final_script_log.txt;最终数据(价格、代码、获胜者、报价等)需打印在日志末尾。step <n> action: <原因与操作>
- 浏览器模式为本地:每次Playwright运行都会通过启动一个全新的Firefox浏览器。无持久浏览器状态——每个脚本都从零开始重建状态。(使用Firefox而非Chromium是因为部分网站在Chromium下会因TLS/H2指纹识别问题出现
playwright.firefox.launch(headless=True)错误。)ERR_HTTP2_PROTOCOL_ERROR - 始终使用。禁止调用
viewport={"width": 1280, "height": 1800}(包括探索、调试和最终运行截图)。page.screenshot(full_page=True)
Workflow
工作流程
-
Plan. Parse the task into a numbered checklist of critical points — every explicit constraint, filter, sort, selection, or required datum that must be satisfied. Write it to:
WORKSPACE_DIR/plan.mdmarkdown# Critical Points - [ ] CP1: <description> - [ ] CP2: <description>Each CP must be independently verifiable from a screenshot or a log line. -
Explore. Run scratch Playwright scripts (heredoc-style — see) to discover stable selectors and confirm filter controls exist. Use
reference/playwright_patterns.mdon saved PNGs to inspect UI state. Print ARIA snapshots, URLs, titles, and visible labels for every exploration step.Read -
Authorin a fresh
final_script.py. Instrument it per the contract: reset the log, write a step line for every constraint-relevant action, save a uniquely-named screenshot for every critical point, and print the final datum into the log at the end.final_runs/run_<id>/ -
Execute the final script once. Capture stdout/stderr.
-
Self-verify (this replaces). Walk
webwright.tools.self_reflection:plan.md- For each CP, identify a screenshot path AND/OR a log line that proves
it. each cited PNG and confirm the evidence is unambiguous (the filter chip is visible, the date matches exactly, the result list reflects the constraint, etc.).
Read - Tick the CP only when evidence is concrete. Be harsh with ambiguous, occluded, or partially-applied states.
- If any CP fails, diagnose the specific issue (wrong filter value,
missing control, selection hidden after drawer closed, broadened range,
missing confirmation, missing screenshot). Fix , re-run inside
final_script.py, and re-verify.final_runs/run_<id+1>/
- For each CP, identify a screenshot path AND/OR a log line that proves
it.
-
Done. Only when every CP inis checked off with cited evidence. Report the final datum to the user.
plan.md
-
规划:将任务拆解为编号的关键点清单——所有必须满足的显式约束、筛选、排序、选择或所需数据。将其写入:
WORKSPACE_DIR/plan.mdmarkdown# 关键点 - [ ] CP1: <描述> - [ ] CP2: <描述>每个关键点都必须能通过截图或日志行独立验证。 -
探索:运行临时Playwright脚本(here-doc格式——详见),发现稳定的选择器并确认筛选控件存在。使用
reference/playwright_patterns.md工具读取保存的PNG图片以检查UI状态。为每个探索步骤打印ARIA快照、URL、标题和可见标签。Read -
编写:在新的
final_script.py目录中编写。按照约定添加监控:重置日志,为每个与约束相关的操作写入步骤行,为每个关键点保存命名唯一的截图,并在日志末尾打印最终数据。final_runs/run_<id>/ -
执行:运行一次最终脚本,捕获标准输出/标准错误。
-
自我验证(替代):对照
webwright.tools.self_reflection逐一检查:plan.md- 为每个关键点确定能证明其完成的截图路径和/或日志行。使用工具读取每个引用的PNG图片,确认证据明确(筛选芯片可见、日期完全匹配、结果列表符合约束等)。
Read - 仅当证据确凿时才勾选关键点。对模糊、遮挡或部分生效的状态严格要求。
- 如果任何关键点未通过,诊断具体问题(筛选值错误、控件缺失、抽屉关闭后选择状态隐藏、范围扩大、缺少确认、缺少截图)。修复,在
final_script.py目录中重新运行并重新验证。final_runs/run_<id+1>/
- 为每个关键点确定能证明其完成的截图路径和/或日志行。使用
-
完成:仅当中的所有关键点都已勾选并附有引用证据时,才向用户报告最终数据。
plan.md
Hard Rules
硬性规则
- One bash command per step; observe its output before issuing the next.
- Use stable selectors and current-run evidence — never guess UI state.
- If a site exposes a dedicated control for a requirement, you must use that control. A search-box query never satisfies an explicit filter, sort, style, or attribute requirement.
- Ranking language (,
cheapest,best-selling,most reviewed,highest-rated,lowest, …) must be grounded in the site's actual sort/filter — not in your own ordering of results.latest - Numeric, date, quantity, and unit constraints are exact. Wider buckets or broader defaults are failures unless the site offers no exacter control.
- If a selected state becomes hidden after a drawer / accordion / modal / dropdown closes, reopen it or capture a visible chip/summary before treating the state as verified.
- Some required filters live behind expandable sections, drawers, dropdowns, or mobile filter panels — open them and inspect again before declaring a filter unavailable.
- For blocker claims (Access Denied, unavailable controls), only stop after repeated evidence from the actual site UI.
- If the task asks for a final datum (code, price, quote, review, winner,
benefit list), state that datum explicitly to the user and append it
to .
final_script_log.txt - Do not install extra packages with pip/apt. ,
playwright,httpx, etc. are already installed.pydantic - Once exists, prefer incremental edits (
final_script.py) over rewriting the whole file.Edit
- 每次执行一个bash命令;观察输出后再发出下一个命令。
- 使用稳定的选择器和当前运行的证据——绝不猜测UI状态。
- 如果网站针对需求提供了专用控件,必须使用该控件。搜索框查询永远无法满足显式的筛选、排序、样式或属性要求。
- 排序类表述(最便宜、最畅销、评论最多、评分最高、最低、最新……)必须基于网站实际的排序/筛选功能——而非你自行对结果排序。
- 数字、日期、数量和单位约束必须精确。除非网站没有更精确的控件,否则使用更宽泛的范围或默认值视为失败。
- 如果选择状态在抽屉/折叠面板/模态框/下拉菜单关闭后隐藏,需重新打开或捕获可见的芯片/摘要,再将状态视为已验证。
- 某些所需筛选器位于可展开区域、抽屉、下拉菜单或移动端筛选面板后——在声明筛选器不可用前,需打开并再次检查。
- 对于阻塞性声明(访问被拒绝、控件不可用),仅在多次从实际网站UI获取证据后才停止尝试。
- 如果任务要求提供最终数据(代码、价格、报价、评论、获胜者、福利列表等),需向用户明确说明该数据并将其追加至。
final_script_log.txt - 禁止使用pip/apt安装额外包。、
playwright、httpx等已预先安装。pydantic - 一旦存在,优先选择增量编辑(
final_script.py)而非重写整个文件。Edit
Reference Files
参考文件
- — browser-launch heredoc skeleton,
reference/playwright_patterns.mdrecipes, screenshot naming, log format.aria_snapshot() - — detailed walk-through of plan → explore → final → self-verify, plus the completion checklist.
reference/workflow.md - — contract for CLI tool mode (
reference/cli_tool_mode.mdtable, reusable function + argparse, import-safety,# Parameterslog line, completion gate).step 0 params:
- —— 浏览器启动的here-doc骨架、
reference/playwright_patterns.md示例、截图命名规则、日志格式。aria_snapshot() - —— 从规划→探索→最终脚本→自我验证的详细流程,以及完成 checklist。
reference/workflow.md - —— CLI工具模式的约定(
reference/cli_tool_mode.md表格、可复用函数+argparse、导入安全性、# 参数日志行、完成条件)。step 0 params:
Slash Commands
斜杠命令
Optional shortcuts under :
commands/- — default one-shot mode.
/webwright:run <task> - — CLI tool mode.
/webwright:craft <task>
The slash commands are convenience templates; the skill also activates
automatically from any prompt whose intent matches its description.
commands/- —— 默认的一次性执行模式。
/webwright:run <task> - —— CLI工具模式。
/webwright:craft <task>
斜杠命令是便捷模板;当任何提示词的意图与本描述匹配时,该技能也会自动激活。