fix: trace request should show bodies from resource#39930
fix: trace request should show bodies from resource#39930Skn0tt merged 1 commit intomicrosoft:mainfrom
Conversation
| } | ||
|
|
||
| if (body) { | ||
| console.log('\n Response body'); |
There was a problem hiding this comment.
Perhaps under an option? Bodies are large, I am not sure always printing 2000 characters for them is a net win. Tbh, same feeling for request bodies.
There was a problem hiding this comment.
Alternatively, we could print the resource path on disk.
| const cwd = process.cwd(); | ||
| const skillSource = path.join(__dirname, 'SKILL.md'); | ||
| const destDir = path.join(cwd, '.claude', 'playwright-trace'); | ||
| const destDir = path.join(cwd, '.claude', 'skills', 'playwright-trace'); |
There was a problem hiding this comment.
Pull request overview
Updates the Playwright Trace CLI’s trace request output to include request/response bodies even when they’re stored as trace resources, and adjusts the trace CLI test fixtures accordingly.
Changes:
- Add CLI output for request body (loaded from
postData._sha1/_fileresources when present). - Add CLI output for response body (loaded from
content._sha1/_fileresources when present). - Extend MCP trace CLI fixtures/tests to generate and assert a POST request with bodies, and adjust
trace install-skilldestination path.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/mcp/trace-cli.spec.ts | Adds an assertion that trace request prints both request and response bodies. |
| tests/mcp/trace-cli-fixtures.ts | Adds a /feedback endpoint and a POST fetch to ensure bodies are present in the trace. |
| packages/playwright-core/src/tools/trace/traceRequests.ts | Loads bodies from trace resources and prints request/response bodies in trace request. |
| packages/playwright-core/src/tools/trace/installSkill.ts | Installs the trace skill under .claude/skills/playwright-trace. |
| if (blob) | ||
| body = await blob.text(); |
There was a problem hiding this comment.
blob.text() converts the entire attached request payload to a string before truncation, which can be very expensive for large bodies; consider reading only the first ~2000 bytes/chars (e.g. via blob.slice(...)) and using blob.size to decide whether to append ....
| if (blob) | |
| body = await blob.text(); | |
| if (blob) { | |
| const maxPreviewBytes = 2000; | |
| const slice = blob.slice(0, maxPreviewBytes); | |
| body = await slice.text(); | |
| if (blob.size > maxPreviewBytes) | |
| body += '...'; | |
| } |
| let body = r.response.content.text; | ||
| const resource = r.response.content._sha1 ?? r.response.content._file; | ||
| if (resource) { | ||
| const blob = await trace.loader.resourceForSha1(resource); | ||
| if (blob) | ||
| body = await blob.text(); | ||
| } |
There was a problem hiding this comment.
Same concern for response bodies: blob.text() loads the full response into a string even though only the first 2000 chars are printed; slicing the blob before decoding avoids large extra allocations for big resources.
This comment has been minimized.
This comment has been minimized.
| playwright-cli tracing-stop | ||
|
|
||
| # Open trace to see DOM state when click was attempted | ||
| npx playwright trace open TODO |
There was a problem hiding this comment.
i'll double-check all these scripts before merging
|
|
||
| export async function installSkill() { | ||
| const cwd = process.cwd(); | ||
| const skillSource = path.join(__dirname, 'SKILL.md'); |
There was a problem hiding this comment.
Shouldn't this SKILL.md file be removed?
| if (r.request.postData.text) { | ||
| const resource = r.request.postData._sha1 ?? r.request.postData._file; | ||
| if (resource) { | ||
| console.log(` ${path.resolve(trace.model.traceUri, 'resources', resource)}`); |
| const resource = r.response.content._sha1 ?? r.response.content._file; | ||
| if (resource) { | ||
| console.log('\n Response body'); | ||
| console.log(` ${path.resolve(trace.model.traceUri, 'resources', resource)}`); |
There was a problem hiding this comment.
Relative to cwd here as well.
| Capture detailed execution traces for debugging and analysis. Traces include DOM snapshots, screenshots, network activity, and console logs. | ||
|
|
||
| ## Basic Usage | ||
| ## Recording a Trace |
There was a problem hiding this comment.
Let's not merge the skill here yet, make a separate PR for it please.
This comment has been minimized.
This comment has been minimized.
Test results for "MCP"1 failed 6295 passed, 360 skipped Merge workflow run. |
…rce (#39951) Co-authored-by: Simon Knott <info@simonknott.de>
resourcestrace install-skillin favour of existing skill