MarketSquare / MarketSquare/robotframework-browser
Add `Set Extra HTTP Headers` keyword to change request headers mid-test
@Snooz82 is already working on this.
Since Aug 6, 2026.
- Dominant language
- Python
- Stars
- 655
- Forks
- 147
- Avg merge
- 5h 27m
- Merged PRs (30d)
- 59
Description
## 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).
```robotframework
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
- [`browserContext.setExtraHTTPHeaders`](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-extra-http-headers)
- [`page.setExtraHTTPHeaders`](https://playwright.dev/docs/api/class-page#page-set-extra-http-headers)
## 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.