Skip to content

feat(mcp): filtering and optional headers/body in browser_network_requests#39672

Merged
yury-s merged 6 commits intomicrosoft:mainfrom
yury-s:feat-mcp-network-body
Mar 17, 2026
Merged

feat(mcp): filtering and optional headers/body in browser_network_requests#39672
yury-s merged 6 commits intomicrosoft:mainfrom
yury-s:feat-mcp-network-body

Conversation

@yury-s
Copy link
Copy Markdown
Member

@yury-s yury-s commented Mar 13, 2026

Enhance the browser_network_requests tool and CLI network command with additional debugging capabilities. Adds URL filtering via regexp (--filter) and optional inclusion of request headers (--request-headers) and request body (--request-body). Also renames includeStatic to static for consistency.

Fixes microsoft/playwright-mcp#1128

Adds `includeBody` option to `browser_network_requests` MCP tool and
`--body` flag to the `network` CLI command to include POST/PUT/PATCH
request bodies in the network log output.
@yury-s yury-s requested a review from Copilot March 13, 2026 22:23
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

Adds an opt-in path to include request bodies in the Playwright MCP network request log output, and exposes it via the CLI network command.

Changes:

  • Add includeBody option to browser_network_requests and render request postData() when enabled.
  • Add --body flag to the network CLI command and map it to the MCP tool option.
  • Add MCP + CLI tests covering default omission and opt-in inclusion of request bodies.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/mcp/network.spec.ts Adds coverage for includeBody option in MCP tool output.
tests/mcp/cli-devtools.spec.ts Adds coverage for network --body CLI flag behavior.
packages/playwright-core/src/tools/cli-daemon/commands.ts Introduces --body CLI option and forwards to MCP tool params.
packages/playwright-core/src/tools/backend/network.ts Implements includeBody schema + request body rendering in network output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

This comment has been minimized.

@yury-s yury-s requested a review from pavelfeldman March 13, 2026 23:23
@github-actions

This comment has been minimized.

@yury-s yury-s changed the title feat(mcp): include request body in network tool output feat(mcp): filtering and optional headers/body in browser_network_requests Mar 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

5405 passed, 172 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

4 flaky ⚠️ [chromium-library] › library/trace-viewer.spec.ts:1230 › should display language-specific locators `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/trace-viewer.spec.ts:1230 › should display language-specific locators `@chromium-ubuntu-22.04-node22`
⚠️ [webkit-library] › library/browsertype-connect.spec.ts:758 › run-server › should upload a folder `@webkit-ubuntu-22.04-node20`
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:297 › should detect mime type `@webkit-ubuntu-22.04-node20`

38691 passed, 846 skipped


Merge workflow run.

@daydaychen
Copy link
Copy Markdown

Great work on adding filtering and request headers/body support! This will be very useful for debugging network issues.

I'd like to suggest adding a complementary tool: browser_get_network_response to retrieve response bodies by request ID.

Use Case

Currently, browser_network_requests shows request metadata (URL, method, headers, payload), but to inspect the actual response body, users need to write custom code with page.on('response'). A dedicated tool would streamline this workflow.

Proposed API

browser_get_network_response: {
  request_id: string;  // From browser_network_requests output
}

Example Workflow

# 1. List requests
browser_network_requests
# Output: [req_123] [GET] https://api.example.com/data

# 2. Get response body
browser_get_network_response: { request_id: "req_123" }
# Output: {"status": "success", "data": [...]}

Implementation Notes

  • Auto-detects content type (JSON, text, images)
  • Truncates large responses (configurable limit)
  • Handles binary content (images as base64 or direct display)
  • Gracefully handles collected responses (memory optimization)

Question

Would this fit within the scope of this PR, or should it be a separate contribution? I have a working implementation if you're interested.

Thanks for driving these improvements to the network tools!

@yury-s yury-s merged commit 4df350b into microsoft:main Mar 17, 2026
39 checks passed
@yury-s yury-s deleted the feat-mcp-network-body branch March 17, 2026 22:49
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.

browser_network_requests tool - support to also return request payload for the POST/PUT requests.

4 participants