Playwright Trace playwright-trace
Inspect Playwright trace files from the command line — list actions, view requests, console, errors, snapshots and screenshots.
- Our test
- —
- not tested yet
- GitHub stars
- 102k
- microsoft/playwright
- Added by
- 0
- members
- Updated
- Dec 6
- commit 2cfa0bc
- Content
- 1 file
- no scripts · 7 KB
- License
- Apache 2.0
- free to use
What our test found
Not tested yet. Our model tries every skill on a realistic request and scores the result, the most popular skills first. Until then, the safety checks on the right still apply.
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:*)
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.
actions, requests, console, errors, and summary accept --json for machine-readable output, with no table headings. Existing filters also apply to JSON output. Action and request ordinals match their detail commands; console ordinals are assigned before filtering.
JSON lists contain these fields:
- Actions:
ordinal,callId,startTime(milliseconds from trace start),duration(milliseconds, ornullfor unfinished actions),title,status(passedorfailed, based on the recorded action error),error(message ornull). - Requests:
ordinal,method,url,status,duration(milliseconds),failure(transfer error ornull). HTTP error responses can have anulltransfer error. - Console:
ordinal,type(console level,stdout, orstderr),text,location(string ornull). - Errors:
type(assertion,stderr,console, orpageError),message,location(string ornull), andstackwhen recorded.assertionincludes recorded test and action errors. Unlike the default errors view, JSON also includes browser console errors, uncaught page errors, and nonempty stderr entries.
Commands
Summary
# Metadata and diagnostic counts for the opened trace
npx playwright trace summary
npx playwright trace summary --jsonThe JSON object contains:
metadata:browser,viewport({ width, height }),platform,testTitle(eachnullwhen unavailable), anddurationin milliseconds.actions:total,passed,failed, andfirstFailed({ ordinal, title }ornull).network:total,ok(completed 2xx/3xx responses), anderrors(HTTP errors or failed transfers). A failed transfer is never counted as successful, even if response headers were received.console.errors: browser console error count.errors:totalerror entries andpageErrors(uncaught page error count).
Action counts describe recorded action errors, not the test's final result. Caught action errors can appear in passing tests; console errors and stderr do not necessarily fail a test.
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 closeActions
# 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-onlyAction 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 HTTP errors or failed transfers
npx playwright trace requests --failedRequest 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 errorsSnapshots
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.pngOnly 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.pngTypical 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