Repository navigation
[Claimed #3460] fix(extension): merge context and page extra HTTP headers - #3579
Open
github-actions[bot] wants to merge 6 commits into
Open
github-actions[bot] wants to merge 6 commits into
github-actions[bot] wants to merge 6 commits into
Conversation
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]>
…60' into external-contributor-pr-3460
Contributor
Author
🦋 Changeset detectedLatest commit: d13a4a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
extraHTTPHeadersand the page-only field ispageExtraHTTPHeaders. 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
pnpm exec vitest run packages/extension/tests/extra-http-headers-concurrency.test.tscontext-v2stayed current, and cleared context headers stayed absent after the older page call completedpageExtraHttpHeadersandcontextExtraHttpHeadersintegration tests against the rebuilt extensiontargetIddeprecation warningsOriginal description
why
context.setExtraHTTPHeaders()andpage.setExtraHTTPHeaders()each send only their own headers, and CDP'sNetwork.setExtraHTTPHeadersreplaces 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
Pagekeeps a copy of the context's headers (contextExtraHTTPHeaders) and builds the set to send withmergedExtraHTTPHeaders(): 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.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.tsandcontextExtraHttpHeaders.test.tscheck the request headers a local server actually receives:--site-per-process,child.testmapped to 127.0.0.1, the same setup asactIframeAttachment.test.ts), a fetch the iframe makes after loading still has the context headers, and the page headers too when both are set.Results:
undefined) and the 3 existing ones pass. With the fix, all 9 pass.iframeNetworkCaptureandactIframeAttachment(12 tests per run), and they passed every time.just checkpasses.pnpm testpasses, including the extension unit tests (1212) and the SDK unit and browser tests.pnpm test:integrationpasses in full (259 tests in 40 files), as do the docs unit tests.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.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()andpage.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
context.setExtraHTTPHeaders()updates existing pages and sends each session its owning page's merged set; new pages pick up the current context headers.Network.enablere-merge current values after the wait, so an older call can't overwrite a newer update or restore cleared headers.Written for commit d13a4a2. Summary will update on new commits.