Skip to content

Add Set Extra HTTP Headers keyword to change request headers mid-test #5115

Description

@Snooz82

Use case

Extra HTTP headers (auth tokens, correlation/tracing IDs, tenant selectors, feature-flag headers) can currently only be set once, at New Context time via extraHTTPHeaders. When a test obtains a fresh token mid-session — after login, after a token refresh, or when switching users — the only way to change headers today is to close the context and create a new one, which throws away all page state, cookies and open pages. Playwright allows updating the headers on a live context (or page) at any time; the library should too.

Proposed keyword / arguments

Set Extra HTTP Headers &{headers} *, scope=Context

  • headers — free named arguments (or a dict) of header name → value; applied to all subsequent requests. Header values must be strings.
  • scope — Context (default): headers apply to every page in the current context, including pages opened later; Page: only requests initiated by the current page (page-level headers are merged over context-level ones, per Playwright semantics).
New Context
New Page    ${URL}/login
# ... perform login, obtain a token ...
Set Extra HTTP Headers    Authorization=Bearer ${token}    X-Correlation-Id=${test_id}
Go To    ${URL}/dashboard

# Override for the current page only
Set Extra HTTP Headers    X-Experiment=variant-b    scope=Page

Playwright API

Implementation notes

  • New RPC in protobuf/playwright.proto carrying the header map plus a page/context flag.
  • node/playwright-wrapper: resolve current page or context from the catalog, call setExtraHTTPHeaders.
  • Python keyword (natural home: Browser/keywords/network.py or playwright_state.py), docs, atest asserting the header arrives server-side (test app echoes request headers) and that scope=Context covers a page opened after the call.

Backwards compatibility

Purely additive: a new keyword; the existing New Context extraHTTPHeaders= argument is untouched and simply provides the initial value the keyword can later replace.

Activity

  1. self-assigned this
    on Aug 6, 2026
  2. added theissue type on Aug 6, 2026
  3. added this to the Ecosystem project milestone on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions