使用 playwright-cli 做网页导航、表单交互、截图、录屏、网络调试、多标签和会话管理。
playwright-cli 驱动真实浏览器完成网页任务playwright-cli优先不要用我:
@playwright/cli,且用户不希望装新工具先确认:
playwright-cli 可执行npm install -g @playwright/cli@latest
playwright-cli --help
如果全局命令不可用:
npx playwright-cli --help
这是默认且优先的规则。
如果多个 subagent、多个 OpenCode / Codex / Claude Code session 会在同一台机器上同时调用 playwright-cli,先遵守这里,再做别的。
run_id 和 agent_idpw-<tool>-<run_id>-<agent_id> 生成 session 名profile/、artifacts/、downloads/、state.json-s=<session>close-all如果你想直接生成一份可分发给 worker 的计划文件,可以先跑:
python playwright-cli/scripts/parallel_run_manifest.py --help
-s=<unique-session>,不要依赖默认 session。--persistent 或 --profile,目录就必须独占,不能共享。snapshot、screenshot、trace、下载文件都写进独立路径。close-all 或 kill-all。e15 这类 ref 只在“同一个 session + 最新 snapshot”里有效;不要跨 session、跨 agent、跨快照传递 ref。--headed。state-save 文件、截图、trace、日志、URL、下载好的文件;不要让两个 agent 共用一个活的浏览器上下文。pw-<tool>-<run_id>-<agent_id>./tmp/playwright/<run_id>/<agent_id>/profile./tmp/playwright/<run_id>/<agent_id>/artifacts./tmp/playwright/<run_id>/<agent_id>/downloads./tmp/playwright/<run_id>/<agent_id>/state.json更多细节见:references/parallel-and-sessions.md
最小工作流:
playwright-cli open https://playwright.dev
playwright-cli snapshot
playwright-cli click e15
playwright-cli press Enter
playwright-cli screenshot
playwright-cli close
核心心智模型:
open 或 gotosnapshot 获取最新 refclick / fill / check / selectclose,或保留 session 继续工作重要习惯:
snapshotsnapshotsnapshot 是主工作流,screenshot 是交付物--filename--persistent、state-save、state-loadopensnapshotconsole / network / screenshot 留证据snapshotfill 或 type 输入snapshotstate-save 或 --persistentconsolenetworktracing-start / tracing-stop更多细节见:references/test-generation.md
playwright-cli open https://example.com
playwright-cli goto https://example.com/login
playwright-cli snapshot
playwright-cli click e3
playwright-cli fill e5 "[email protected]"
playwright-cli press Enter
playwright-cli screenshot --filename=page.png
playwright-cli console
playwright-cli network
playwright-cli state-save auth.json
playwright-cli state-load auth.json
playwright-cli show
默认就是 headless;更多细节见:references/headless-mode.md
snapshot 就直接猜元素 refPLAYWRIGHT_CLI_SESSION--persistent 或 --profile 时复用同一个 profile 目录close-all 或 kill-allplaywright-cli/references/parallel-and-sessions.md - 需要协调多个 worker、管理 session、做文件式交接时再读playwright-cli/references/headless-mode.md - 需要稳定 headless 行为或远程环境细节时再读playwright-cli/references/test-generation.md - 需要把真实流程翻译成 Playwright test 时再读playwright-cli/scripts/parallel_run_manifest.pypython -m unittest "playwright-cli/tests/test_playwright_cli_smoke.py"
python -m unittest "playwright-cli/tests/test_parallel_docs.py" "playwright-cli/tests/test_parallel_run_manifest.py"