Skip to content

[Claimed #3460] fix(extension): merge context and page extra HTTP headers - #3579

Open
github-actions[bot] wants to merge 6 commits into
mainfrom
external-contributor-pr-3460
Open

github-actions[bot] wants to merge 6 commits into
mainfrom
external-contributor-pr-3460

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Mirrored from external contributor PR #3460 after approval by @shrey150.

Original author: @EsawAdhana
Original PR: #3460
Approved source head SHA: bab439dac67d57df542447253fb9807718a9ce00

@EsawAdhana, please continue any follow-up discussion on this mirrored PR. When the external PR gets new commits, this same internal PR will be marked stale until the latest external commit is approved and refreshed here.

Maintainer follow-up

An older page header update could wait for Network.enable, then overwrite a newer context update or restore headers that had been cleared. Header writes now merge current values after that wait. Context writes also resolve the current session owner after the wait, including when an iframe acquires an owner while the call is pending.

The context field is now extraHTTPHeaders and the page-only field is pageExtraHTTPHeaders. These are internal fields; the public API is unchanged. The existing extension, TypeScript SDK, and Python SDK patch changeset covers this correction.

Early requests made before cross-site iframe adoption remain tracked separately in #3580.

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
pnpm exec vitest run packages/extension/tests/extra-http-headers-concurrency.test.ts 11 passed; the same suite had 9 failures and 2 passing controls before the fix Covers delayed page/context updates, clears, ownerless sessions, ownership changes, and iframe adoption
Local Chromium fault-injection harness with a local HTTP server (kept outside the committed diff) Both cases passed: context-v2 stayed current, and cleared context headers stayed absent after the older page call completed Delays one real CDP response; verifies HTTP requests after both calls resolve
Existing pageExtraHttpHeaders and contextExtraHttpHeaders integration tests against the rebuilt extension 9 passed Covers merging, replacement, case-insensitive precedence, clearing, and adopted cross-site iframe requests
Related context lifecycle, iframe adoption, network capture, and CDP event unit tests 48 passed across 5 files Checks the surrounding attachment behavior
Extension build and typecheck; formatting, lint, and changeset validation Passed; lint reports only two existing targetId deprecation warnings Local checks for the changed extension code and regression tests

Original description

why

context.setExtraHTTPHeaders() and page.setExtraHTTPHeaders() each send only their own headers, and CDP's Network.setExtraHTTPHeaders replaces the whole set, so whichever one runs last wipes out the other. Separately, when a page adopts a cross-site iframe's session it sends its own headers even when they're the default {}, which clears the context headers that session got before it resumed, so requests the iframe makes after loading go out without them. Fixes #3459.

what changed

  • Page keeps a copy of the context's headers (contextExtraHTTPHeaders) and builds the set to send with mergedExtraHTTPHeaders(): the context's headers with the page's own on top. Header names are compared case-insensitively, so a page header also replaces a context header that only differs in case.
  • Page.setExtraHTTPHeaders() sends the merged set to all of its sessions.
  • BrowserContext.setExtraHTTPHeaders() updates every page's copy and sends each session its owning page's merged set (sessions without a page still get the context headers). A newly created page picks up the current context headers when it's registered.
  • Page.adoptOopifSession() sends the merged set, and skips sending when it's empty so it can't erase the context headers.
  • One sentence in the context and page reference docs (TypeScript, Python, Go) saying the two sets are sent together and the page's value wins.

No protocol or SDK code changes, so the Python and Go SDKs get this through the extension. The changeset bumps the extension and both SDKs as patches, like other extension-only fixes.

test plan

New integration tests in pageExtraHttpHeaders.test.ts and contextExtraHttpHeaders.test.ts check the request headers a local server actually receives:

  • context headers survive setting page headers, and page headers survive setting context headers later;
  • a page header wins over a context header with the same name (different casing);
  • clearing page headers keeps the context headers;
  • in a cross-site iframe (--site-per-process, child.test mapped to 127.0.0.1, the same setup as actIframeAttachment.test.ts), a fetch the iframe makes after loading still has the context headers, and the page headers too when both are set.

Results:

  • On main, the 6 new tests fail (the missing header comes back undefined) and the 3 existing ones pass. With the fix, all 9 pass.
  • I ran the new header tests 5 more times together with iframeNetworkCapture and actIframeAttachment (12 tests per run), and they passed every time.
  • just check passes. pnpm test passes, including the extension unit tests (1212) and the SDK unit and browser tests. pnpm test:integration passes in full (259 tests in 40 files), as do the docs unit tests.
  • On the Python side, the SDK suite passes in full on Python 3.11, the version in packages/sdk-python/.python-version (1096 passed, 10 skipped), and so do the core middleware (147), Deep Agents (12 and 61) and catalog cookbook tests.
  • I also ran the three scenarios end to end through the Python SDK against a local server. On main, the request was missing the context header after setting page headers, and the cross-site iframe's fetch had no headers at all. With this branch, both sets arrive, the page's value wins on a clash, and the iframe keeps the context headers.

One thing this doesn't change: a cross-site iframe's very first navigation only gets the context headers, because its owning page isn't known yet when the session is paused. The page's headers apply from adoption onward, same as before.

I used Claude Code to find this bug, write the change and tests, and run the checks above on my Mac.

🤖 Generated with Claude Code


Summary by cubic

Fixes extra HTTP headers so context.setExtraHTTPHeaders() and page.setExtraHTTPHeaders() send both sets together instead of the last call replacing the other. Also prevents page adoption of a cross-site iframe session from wiping out the context headers that session already had.

What changed

  • Pages now send the merged set: context headers with the page's own on top, with the page's value winning on a clash (compared case-insensitively).
  • context.setExtraHTTPHeaders() updates existing pages and sends each session its owning page's merged set; new pages pick up the current context headers.
  • Header writes that wait for Network.enable re-merge current values after the wait, so an older call can't overwrite a newer update or restore cleared headers.
  • Iframe session adoption sends the merged set only when non-empty, so it can't erase the context headers.
  • Updated TypeScript, Python, and Go docs to note the two sets are sent together.

Written for commit d13a4a2. Summary will update on new commits.

View guided diff Turn on auto-fix

EsawAdhana and others added 3 commits November 20, 2026 16:39
These fail on main: whichever of context.setExtraHTTPHeaders() and
page.setExtraHTTPHeaders() runs last replaces the other's headers, and a
cross-site iframe loses the context headers once its page adopts it.

Refs #3459

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Network.setExtraHTTPHeaders replaces the whole set, so the context and the
page now always send the merged set: the context's headers with the page's
own on top, compared case-insensitively. Adopting a cross-site iframe no
longer sends an empty set that erased the context headers.

Fixes #3459

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions
github-actions Bot requested a review from a team as a code owner November 30, 2026 02:03
@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

This mirrored PR tracks external contributor PR #3460 at source SHA bab439dac67d57df542447253fb9807718a9ce00, approved by @shrey150.
Original PR: #3460

When the external PR gets new commits, this same internal PR will be refreshed in place after the latest external commit is approved.

@changeset-bot

changeset-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d13a4a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-code Patch
@browserbasehq/stagehand-integrations-codex Patch
@browserbasehq/stagehand-integrations-cursor Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-fx Patch
@browserbasehq/stagehand-integrations-mastra Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch
@browserbasehq/stagehand-integrations-eve-harness Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context and page extra HTTP headers replace each other, and context headers drop in cross-site iframes

2 participants