Playwright 追踪文件检查
playwright-trace
从命令行检查 Playwright trace 文件——列出操作、查看请求、控制台、错误、快照和屏幕截图。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 10w
- Forks
- 6.9k
01 前言 Front Matter
- name
- playwright-trace
- description
- Inspect Playwright trace files from the command line — list actions, view requests, console, errors, snapshots and screenshots.
- allowed-tools
- Bash(npx playwright trace:*)
02 资源文件 10
- 参考文档agents/artifact-analyzer.md2.4 KB
- 参考文档agents/opportunity-reviewer.md1.7 KB
- 参考文档agents/skeptic-reviewer.md1.5 KB
- 参考文档agents/web-researcher.md1.6 KB
- 参考文档bmad-manifest.json494 B
- 参考文档prompts/contextual-discovery.md2.5 KB
- 参考文档prompts/draft-and-review.md3.9 KB
- 参考文档prompts/finalize.md3.8 KB
- 参考文档prompts/guided-elicitation.md3.3 KB
- 参考文档resources/brief-template.md2.3 KB
03 SKILL.md 正文
Playwright Trace CLI
Inspect .zip trace files produced by Playwright tests without opening a browser.
Workflow
- Start with
trace open <trace.zip>to extract the trace and see its metadata. - Use
trace actionsto see all actions with their action IDs. - Use
trace action <action-id>to drill into a specific action — see parameters, logs, source location, and available snapshots. - Use
trace requests,trace console, ortrace errorsfor cross-cutting views. - Use
trace snapshot <action-id>to get the DOM snapshot, or run a browser command against it. - Use
trace closeto remove the extracted trace data when done.
All commands after open operate on the currently opened trace — no need to pass the trace file again. Opening a new trace replaces the previous one.
Commands
Open a trace
# Extract trace and show metadata: browser, viewport, duration, action/error counts
npx playwright trace open <trace.zip>
Close a trace
# Remove extracted trace data
npx playwright trace close
Actions
# List all actions as a tree with action IDs and timing
npx playwright trace actions
# Filter by action title (regex, case-insensitive)
npx playwright trace actions --grep "click"
# Only failed actions
npx playwright trace actions --errors-only
Action details
# Show full details for one action: params, result, logs, source, snapshots
npx playwright trace action <action-id>
The action command displays available snapshot phases (before, action, after) and the exact command to extract them.
Requests
# All network requests: start time (on the `trace actions` clock), method, status, URL, duration, size
npx playwright trace requests
# Filter by URL pattern
npx playwright trace requests --grep "api"
# Filter by HTTP method
npx playwright trace requests --method POST
# Only failed requests (status >= 400)
npx playwright trace requests --failed
Request details
# Show full details for one request: headers, body, security
npx playwright trace request <request-id>
Console
# All console messages and stdout/stderr
npx playwright trace console
# Only errors
npx playwright trace console --errors-only
# Only browser console (no stdout/stderr)
npx playwright trace console --browser
# Only stdout/stderr (no browser console)
npx playwright trace console --stdio
# Filter by message text pattern
npx playwright trace console --grep "failed to fetch"
Errors
# All errors with stack traces and associated actions
npx playwright trace errors
Snapshots
The snapshot command loads the DOM snapshot for an action into a headless browser and runs a single browser command against it. Without a browser command, it returns the accessibility snapshot.
# Get the accessibility snapshot (default)
npx playwright trace snapshot <action-id>
# Use a specific phase
npx playwright trace snapshot <action-id> --phase before
# Run eval to query the DOM
npx playwright trace snapshot <action-id> -- eval "document.title"
npx playwright trace snapshot <action-id> -- eval "document.querySelector('#error').textContent"
# Eval on a specific element ref (from the snapshot)
npx playwright trace snapshot <action-id> -- eval "el => el.getAttribute('data-testid')" e5
# Take a screenshot of the snapshot
npx playwright trace snapshot <action-id> -- screenshot
# Redirect output to a file
npx playwright trace snapshot <action-id> -- eval "document.body.outerHTML" --filename=page.html
npx playwright trace snapshot <action-id> -- screenshot --filename=screenshot.png
Only three browser commands are useful on a frozen snapshot: snapshot, eval, and screenshot.
Attachments
# List all trace attachments
npx playwright trace attachments
# Extract an attachment by its number
npx playwright trace attachment 1
npx playwright trace attachment 1 -o out.png
Typical investigation
# 1. Open the trace and see what's inside
npx playwright trace open test-results/my-test/trace.zip
# 2. What actions ran?
npx playwright trace actions
# 3. Which action failed?
npx playwright trace actions --errors-only
# 4. What went wrong?
npx playwright trace action 12
# 5. What did the page look like at that moment?
npx playwright trace snapshot 12
# 6. Query the DOM for more detail
npx playwright trace snapshot 12 -- eval "document.querySelector('.error-message').textContent"
# 7. Any relevant network failures?
npx playwright trace requests --failed
# 8. Any console errors?
npx playwright trace console --errors-only
04 同仓库更多 Skills
Playwright 组件测试搭建
playwright-component-testing
使用 story 画廊通过 Playwright 搭建组件测试——基于内置的 mount fixture 生成 stories 和画廊开发页面,无需专门的组件测试运行时。在需要使用 Playwright 隔离测试 React 或 Vue 组件,或从 @playwright/experimental-ct-react / -vue 迁移时使用。
Playwright 浏览器自动化
playwright-cli
自动化浏览器交互、测试网页并处理 Playwright 测试。
Playwright 测试结果查询
playwright-test-results
从聚合的 DuckDB 数据库中查询 Playwright CI 测试结果。无需在 GitHub 构建产物中逐一翻找,即可回答有关不稳定测试(flaky tests)、失败率、缓慢测试以及每次运行/SHA/PR 结果的问题。
Playwright 发布说明撰写
playwright-release-notes
为 Playwright 版本发布撰写发布说明——包括 docs/src/release-notes-js.md 中的 Node.js 说明,以及 Python、Java 和 .NET 的翻译版本,还有每种语言版本的 GitHub markdown 文档。当用户要求撰写、翻译或发布发布说明时使用。
Playwright CI 与发布运维
playwright-devops
Playwright 的 DevOps 工作流——CI 失败分析、工作流调试和发布操作。
Playwright 功能开发指南
playwright-dev
讲解如何开发 Playwright——添加 API、MCP 工具、CLI 命令以及供应商(vendor)依赖。