Open whimboo opened 1 week ago
Note: We've also seen requests from customers for setting multiple headers with the same header name.
@whimboo Considering we had discussion around how session.subscribe
/session.unsubscribe
and how it can become very confusing (here we may hit this as well), I would think about using the same logic we do for script.AddPreloadScript
and network.addInterception
where we return an ID to be used for the removal operation.
The Browser Testing and Tools Working Group just discussed Emulation - Support for specifying extra HTTP headers
.
It would be helpful for clients to have the ability to specify extra HTTP headers globally or for a specific set of browsing contexts. While custom HTTP headers can currently be set through network interception, it would simplify the process if we allowed headers to be set via a single command without relying on interception. These headers could then be automatically applied to all network activity within the specified browsing contexts.
This enhancement would enable more flexible testing scenarios, where each context can simulate different client headers, such as language settings (see #774), authentication tokens, or custom headers for API requests.
Use Cases
Multi-Context Testing: Simulating different user agents, authentication tokens, or localization settings (e.g.,
Accept-Language
) across various browsing contexts. This would help developers test how their application behaves when accessed by different types of clients in parallel.A/B Testing: Using different headers (e.g., feature flags) to simulate A/B testing environments within the same browser instance, but isolated to separate browsing contexts.
Authentication and Security Testing: Simulating different users with different authentication headers in separate tabs or frames. This allows the testing of security mechanisms and session isolation between tabs. This is some feature Cypress would benefit from given that it has to send a fixed set of authentication headers.
Proposal
Introduce an API that allows setting extra HTTP headers globally or for specific browsing contexts. The API would accept a list of context IDs along with the headers to be applied for each context.
The API could look like:
Command to set extra HTTP headers for multiple contexts:
Command to clear extra HTTP headers:
Benefits
Accept-Language
header) or client-specific behavior based on custom headers.Questions
headers
field and entries are specified?