Skip to content

feat: add set_extra_http_headers tool for Network.setExtraHTTPHeaders#1176

Open
pedrodurek wants to merge 1 commit intoChromeDevTools:mainfrom
pedrodurek:feature/set-extra-http-headers
Open

feat: add set_extra_http_headers tool for Network.setExtraHTTPHeaders#1176
pedrodurek wants to merge 1 commit intoChromeDevTools:mainfrom
pedrodurek:feature/set-extra-http-headers

Conversation

@pedrodurek
Copy link
Copy Markdown

Summary

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

Closes #1175

Tool Definition

  • Name: set_extra_http_headers
  • Category: Network (alongside list_network_requests and get_network_request)
  • Schema: headers — a Record<string, string> of header name-value pairs
  • 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 {}
    • Returns a confirmation message listing the header names set, or "cleared" when empty

Use Case

This enables setting custom HTTP headers on all requests — including the initial document navigation and <script> tag loads — which initScript cannot do since it runs after the document is already fetched.

Changes

  • src/tools/network.ts — Added setExtraHTTPHeaders page tool using definePageTool
  • tests/tools/network.test.ts — Added 3 test cases:
    1. Verifies headers arrive at the server
    2. Verifies clearing headers with {}
    3. Verifies headers persist across navigations

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Collaborator

@OrKoN OrKoN left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I think we should align with the suggestion in this comment #1175 (comment) and add this to the emulation tool.

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.

Feature request: set_extra_http_headers tool for Network.setExtraHTTPHeaders

2 participants