Skip to content

fix: trace request should show bodies from resource#39930

Merged
Skn0tt merged 1 commit intomicrosoft:mainfrom
Skn0tt:trace-feedback
Mar 31, 2026
Merged

fix: trace request should show bodies from resource#39930
Skn0tt merged 1 commit intomicrosoft:mainfrom
Skn0tt:trace-feedback

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented Mar 30, 2026

  • the trace I tested with had the bodies in resources
  • mime type is already present in headers, not needed again
  • response body is just as important as request body
  • removetrace install-skill in favour of existing skill

@Skn0tt Skn0tt requested review from Copilot and dgozman March 30, 2026 13:28
@Skn0tt Skn0tt changed the title fix: trace requests should show bodies from resource fix: trace request should show bodies from resource Mar 30, 2026
}

if (body) {
console.log('\n Response body');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/_file resources when present).
  • Add CLI output for response body (loaded from content._sha1/_file resources when present).
  • Extend MCP trace CLI fixtures/tests to generate and assert a POST request with bodies, and adjust trace install-skill destination 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.

Comment on lines +121 to +122
if (blob)
body = await blob.text();
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ....

Suggested change
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 += '...';
}

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +149
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();
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

playwright-cli tracing-stop

# Open trace to see DOM state when click was attempted
npx playwright trace open TODO
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll double-check all these scripts before merging


export async function installSkill() {
const cwd = process.cwd();
const skillSource = path.join(__dirname, 'SKILL.md');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relative to cwd please.

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)}`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not merge the skill here yet, make a separate PR for it please.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [msedge] › mcp/files.spec.ts:106 › clicking on download link emits download @mcp-windows-latest

6295 passed, 360 skipped


Merge workflow run.

@Skn0tt Skn0tt merged commit 9c68b52 into microsoft:main Mar 31, 2026
10 of 11 checks passed
dgozman pushed a commit to dgozman/playwright that referenced this pull request Mar 31, 2026
dgozman added a commit that referenced this pull request Mar 31, 2026
…rce (#39951)

Co-authored-by: Simon Knott <info@simonknott.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants