Skip to content

[Bug]: [MCP] browser_route silently drops headers when mocking response with status or body #43245

Closed

Description

@alok-108

What's going on?

When configuring a mock route with browser_route using status or body, custom response headers supplied in headers: ["Name: Value"] are silently ignored and never returned in the fulfilled mock response.

For example, when configuring a mock route with custom response headers or CORS headers:

{
  "pattern": "**/api/data",
  "status": 200,
  "body": "{\"ok\": true}",
  "headers": [
    "X-Custom-Res: test-value",
    "Access-Control-Allow-Origin: *"
  ]
}

When the page fetches /api/data:

fetch('/api/data').then(r => {
  console.log(r.headers.get('x-custom-res')); // null
  console.log(r.headers.get('access-control-allow-origin')); // null
});

The response received by the page does not contain any of the custom headers specified in headers.

Reproduction Screenshots

1. Repro — Headers dropped when fulfilling mock response:
browser_route Response Headers Dropped

2. Fix & MCP Test Verification (11 tests pass):
Fix and verification passing in route.spec.ts

Why does this happen?

In packages/playwright-core/src/tools/backend/route.ts:

  1. params.headers is parsed into addHeaders.
  2. When fulfilling a mock response (params.body !== undefined || params.status !== undefined), the handler calls:
await route.fulfill({
  status: params.status ?? 200,
  contentType: params.contentType,
  body: params.body,
});

headers: addHeaders is omitted from the options passed to route.fulfill(), discarding all specified response headers.

Expected behavior

When fulfilling a mock response, headers: addHeaders should be passed to route.fulfill() so that custom response headers (CORS headers, cache headers, auth headers) are returned to the caller.

Environment

  • @playwright/mcp, Playwright main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions