Skip to content

Feature request: set_extra_http_headers tool for Network.setExtraHTTPHeaders #1175

@pedrodurek

Description

@pedrodurek

Feature Request

Problem

There is currently no way to set custom HTTP headers on all requests (including the initial document navigation and <script> tag loads) via the MCP tools.

The navigate_page tool supports initScript, which can intercept fetch() and XMLHttpRequest calls at runtime. However, initScript runs after the document is already fetched — it cannot set headers on:

  • The initial HTML document request (navigation)
  • <script src="..."> tag loads (parsed from HTML)
  • CSS, image, and font loads

Proposed Solution

Add a set_extra_http_headers tool that calls Puppeteer's page.setExtraHTTPHeaders() (which uses CDP Network.setExtraHTTPHeaders under the hood).

Tool definition:

name: set_extra_http_headers
description: Set extra HTTP headers to be sent with every request. Headers persist until cleared. Pass an empty object to clear.
schema:
  headers:
    type: object
    description: "Header name-value pairs, e.g. {\"X-Custom\": \"value\"}"

Behavior:

  • Headers apply to ALL subsequent requests on the selected page (document, scripts, fetch, XHR, images, etc.)
  • Headers persist across navigations until explicitly cleared with {}
  • Fits naturally in the existing network category alongside list_network_requests and get_network_request

Use Case

We use chrome-devtools-mcp for visual regression testing of a Shopify storefront widget. The widget's JS bundle is served via a <script> tag in the HTML. To test a PR branch, the storefront server needs to see X-Promise-Tophat: <branch> on the document request to serve the branch-specific bundle URL.

Currently we work around this by using a separate tool (agent-browser) that supports --headers via CDP. Having set_extra_http_headers in chrome-devtools-mcp would eliminate this workaround.

Implementation Notes

The implementation should be straightforward since the MCP already has access to the Puppeteer page object:

// In tools/network.ts
await page.setExtraHTTPHeaders(params.headers);

This is a one-liner on top of existing Puppeteer infrastructure.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions