[Feature]: Add --json output to trace CLI commands and add trace summary command
Motivation
Follow-up to discussion on #44377:
"From our experience, agents are better in figuring out the problem from traces than an automatic diff tool. We can improve the output of other
npx playwright tracecommands to make this usecase easier. If you have ideas, please file an issue."
When coding agents or automated CI tools inspect traces via npx playwright trace, parsing ANSI-formatted terminal tables (e.g. from trace actions, trace requests) requires brittle regex and heuristic text stripping. Additionally, obtaining a quick diagnostic overview requires running multiple distinct commands sequentially.
Providing structured --json output across existing inspection commands and adding a compact trace summary command enables agents and automation scripts to consume trace data directly and reliably.
Proposed Solution
-
--jsonoption on existing commands:npx playwright trace actions [options] [--json]Outputs structured array of actions:ordinal,callId,startTime,duration,title,status(passed|failed),error.npx playwright trace requests [options] [--json]Outputs structured array of network requests:ordinal,method,url,status,duration,failure.npx playwright trace console [options] [--json]Outputs structured array of console events:ordinal,type,text,location.npx playwright trace errors [options] [--json]Outputs structured array of errors:type(assertion|stderr|console|pageError),message,location.
-
npx playwright trace summary [--json]: Provides a high-level diagnostic summary of the opened trace:- Metadata: browser, viewport, platform, test title, total duration.
- Action overview: total actions, count of passed vs failed actions, and ordinal/title of the first failing action (if any).
- Network overview: total HTTP requests, count of successful (2xx/3xx) vs error (4xx/5xx/failed) requests.
- Console & Error overview: error count and uncaught page error count.
Opened PR #44428 for this.
Hi @Harshit-2208, thank you for the interest! As the author of this issue, I already implemented this feature and submitted PR #44397 on Nov 25, which is currently open and awaiting maintainer review.
Hi, I'm the Playwright bot. I started triaging this issue on Linux: agent run
Hi, I'm the Playwright bot and I checked the trace commands and both linked proposals.
Implemented in a proposal. At main commit f1b88380ff01eeb677a8779caacbdd274aae819b (1.66.0-next), the four inspection commands reject --json, and trace summary does not exist. The proposal adds both, keeps the existing text views, and documents the JSON fields. The summary uses the currently opened trace and does not infer a test verdict from action errors.
Verification on Linux
- All eight updated or new acceptance tests fail without the implementation.
- The complete trace CLI suite passes: 25 tests. This suite is explicitly Chrome-only; selecting Firefox and WebKit skips its 50 cases.
- The neighboring tracing suite passes on Chromium, Firefox, and WebKit: 12 tests.
- The full build, lint, documentation, and type checks pass.
- Coverage includes filtered JSON, stable ordinals, empty filtered results, all four error categories, and failed transfers after successful HTTP headers.
Draft PR: https://github.com/microsoft/playwright/pull/44459
Triaged on Linux by the Playwright bot - agent run
Updated #44397 to align with the triage specification in #44459:
- Scoped
trace summaryto the currently loaded trace session. - Extracted shared action and error collectors across trace CLI modules.
- Updated network summary statistics to track successful vs error responses.
- Synced with upstream main; all unit tests and lint checks pass.