[feat]: add `context.setExtraHTTPHeaders()`
Merged
SE
9mo ago+224+224+012345678901234567890123456789-0-0-0123456789
why
- to enable users to set headers to be included in every request created by every page within the
context
what changed
- added a new function
context.setExtraHTTPHeaders()which calls theNetwork.setExtraHTTPHeadersCDP command on all existing sessions - we also call
Network.setExtraHTTPHeaderswith the user defined headers whenever we attach to a new target (viaonAttachedToTarget) - if there is a rejected promise when headers are being set, a
StagehandSetExtraHTTPHeadersErrorwill be thrown
test plan
- added an e2e test to confirm that headers are being correctly set by listening to
Network.requestWillBeSentand inspecting headers - also added unit tests to confirm that the custom error is being thrown correctly when promises reject
Summary by cubic
Adds context.setExtraHTTPHeaders() to set default HTTP headers on every request from all pages in a context. Implements STG-1411; applies to current sessions and newly attached targets after Network.enable.
- New Features
- New API: context.setExtraHTTPHeaders(headers) sends Network.enable then Network.setExtraHTTPHeaders to each active session; repeats on attach for new targets.
- Public error: StagehandSetExtraHTTPHeadersError with per-session failure details.
- Tests: e2e verifies navigation headers; unit tests cover multi-session send and error reporting; public error type is exported.