Open vEpiphyte opened 10 months ago
I can repro with WebKit and Chromium. Passes in Firefox:
diff --git a/tests/page/page-set-extra-http-headers.spec.ts b/tests/page/page-set-extra-http-headers.spec.ts
index 284621edd..0a6a6c74f 100644
--- a/tests/page/page-set-extra-http-headers.spec.ts
+++ b/tests/page/page-set-extra-http-headers.spec.ts
@@ -29,6 +29,22 @@ it('should work @smoke', async ({ page, server }) => {
expect(request.headers['baz']).toBe(undefined);
});
+it('should set it on WebSocket connections', async ({ page, server }) => {
+ await page.setExtraHTTPHeaders({
+ foo: 'bar',
+ });
+ const webSocketRequestPromise = server.waitForWebSocketConnectionRequest();
+ await page.evaluate(port => {
+ let cb;
+ const result = new Promise(f => cb = f);
+ const ws = new WebSocket('ws://localhost:' + port + '/ws');
+ ws.addEventListener('open', () => { ws.close(); cb(); });
+ return result;
+ }, server.PORT);
+ const webSocketRequest = await webSocketRequestPromise;
+ expect(webSocketRequest.headers['foo']).toBe('bar');
+});
+
it('should work with redirects', async ({ page, server }) => {
server.setRedirect('/foo.html', '/empty.html');
await page.setExtraHTTPHeaders({
Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.
Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.
Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.
Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.
Hi! It's important bug, blocks writing tests for projects with ws, any ideas how to fix it?
@aletzal I've refiled this per @pavelfeldman 's note above as https://github.com/microsoft/playwright/issues/32247
System info
Scenario: I am testing an application that is to be deployed behind an AWS Application Load Balancer. The ABLB is configured to inject additional headers into all HTTP traffic that it services. I am attempting to use playwright to mimic that behavior by setting those additional headers on the Playwright. This works for regular HTTP requests, but does not inject the additional HTTP headers when the application makes a WebSocket connection to the server.
Source code
I've modified the playwright tests to demonstrate the lack of headers being sent:
Produces the following output:
Expected
I expect the HTTP 101 requests ( made to upgrade a connection to a websocket ) to include the headers added to the page.
I have tried setting additional headers with the following APIs:
https://playwright.dev/python/docs/api/class-browser#browser-new-context https://playwright.dev/python/docs/api/class-browsercontext#browser-context-set-extra-http-headers https://playwright.dev/python/docs/api/class-page#page-set-extra-http-headers
These API docs imply that all connections will have these additional headers added to them.
Actual
In all my test cases, the extra headers are present on non-websocket requests. The HTTP 101 requests made to upgrade a connection do not have the additional headers available on them.