Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(bidi): fix header overrides for redirects (#38774)

Holger Benla6b434f6e7ef
diff --git a/packages/playwright-core/src/server/bidi/bidiNetworkManager.ts b/packages/playwright-core/src/server/bidi/bidiNetworkManager.ts
index 8581808560..2a646c673b 100644
--- a/packages/playwright-core/src/server/bidi/bidiNetworkManager.ts
+++ b/packages/playwright-core/src/server/bidi/bidiNetworkManager.ts
@@ -64,12 +64,16 @@ export class BidiNetworkManager {
if (redirectedFrom)
this._deleteRequest(redirectedFrom._id);
let route;
+ let headersOverride: types.HeadersArray | undefined;
if (param.intercepts) {
// We do not support intercepting redirects.
if (redirectedFrom) {
let params = {};
- if (redirectedFrom._originalRequestRoute?._alreadyContinuedHeaders)
- params = toBidiRequestHeaders(redirectedFrom._originalRequestRoute._alreadyContinuedHeaders ?? []);
+ if (redirectedFrom._originalRequestRoute?._alreadyContinuedHeaders) {
+ const originalHeaders = fromBidiHeaders(param.request.headers);
+ headersOverride = network.applyHeadersOverrides(originalHeaders, redirectedFrom._originalRequestRoute._alreadyContinuedHeaders);
+ params = toBidiRequestHeaders(headersOverride);
+ }
this._session.sendMayFail('network.continueRequest', {
request: param.request.request,
@@ -79,7 +83,7 @@ export class BidiNetworkManager {
route = new BidiRouteImpl(this._session, param.request.request);
}
}
- const request = new BidiRequest(frame, redirectedFrom, param, route);
+ const request = new BidiRequest(frame, redirectedFrom, param, route, headersOverride);
this._requests.set(request._id, request);
this._page.frameManager.requestStarted(request.request, route);
}
@@ -236,14 +240,21 @@ class BidiRequest {
// store the first and only Route in the chain (if any).
_originalRequestRoute: BidiRouteImpl | undefined;
- constructor(frame: frames.Frame, redirectedFrom: BidiRequest | null, payload: bidi.Network.BeforeRequestSentParameters, route: BidiRouteImpl | undefined) {
+ constructor(
+ frame: frames.Frame,
+ redirectedFrom: BidiRequest | null,
+ payload: bidi.Network.BeforeRequestSentParameters,
+ route: BidiRouteImpl | undefined,
+ headersOverride: types.HeadersArray | undefined
+ ) {
this._id = payload.request.request;
if (redirectedFrom)
redirectedFrom._redirectedTo = this;
// TODO: missing in the spec?
const postDataBuffer = null;
- this.request = new network.Request(frame._page.browserContext, frame, null, redirectedFrom ? redirectedFrom.request : null, payload.navigation ?? undefined, payload.request.url,
- resourceTypeFromBidi(payload.request.destination, payload.request.initiatorType, payload.initiator?.type), payload.request.method, postDataBuffer, fromBidiHeaders(payload.request.headers));
+ this.request = new network.Request(frame._page.browserContext, frame, null, redirectedFrom ? redirectedFrom.request : null, payload.navigation ?? undefined,
+ payload.request.url, resourceTypeFromBidi(payload.request.destination, payload.request.initiatorType, payload.initiator?.type), payload.request.method,
+ postDataBuffer, headersOverride || fromBidiHeaders(payload.request.headers));
// "raw" headers are the same as "provisional" headers in Bidi.
this.request.setRawRequestHeaders(null);
this.request._setBodySize(payload.request.bodySize || 0);
diff --git a/tests/bidi/expectations/moz-firefox-nightly-library.txt b/tests/bidi/expectations/moz-firefox-nightly-library.txt
index 69eb69538a..c4670bd364 100644
--- a/tests/bidi/expectations/moz-firefox-nightly-library.txt
+++ b/tests/bidi/expectations/moz-firefox-nightly-library.txt
@@ -1,3 +1,4 @@
+library/agent-perform.spec.ts › retrieve a secret [timeout]
library/browsercontext-add-cookies.spec.ts › should set cookies with SameSite attribute and no secure attribute [fail]
library/browsercontext-basic.spec.ts › fetch with keepalive should throw when offline [fail]
library/browsercontext-basic.spec.ts › should close all belonging pages once closing context [fail]
@@ -56,9 +57,11 @@ library/browsercontext-viewport.spec.ts › should support touch with null viewp
library/browsertype-connect.spec.ts › launchServer › should be able to connect 20 times to a single server without warnings [timeout]
library/browsertype-connect.spec.ts › launchServer › should save download [fail]
library/browsertype-connect.spec.ts › launchServer › should saveAs videos from remote browser [timeout]
+library/browsertype-connect.spec.ts › run-server › should be able to connect 20 times to a single server without warnings [timeout]
library/browsertype-connect.spec.ts › run-server › should save download [fail]
library/browsertype-connect.spec.ts › run-server › should saveAs videos from remote browser [timeout]
library/browsertype-launch.spec.ts › should reject if launched browser fails immediately [fail]
+library/capabilities.spec.ts › should play video @smoke [timeout]
library/channels.spec.ts › should work with the domain module [timeout]
library/chromium/chromium.spec.ts › http credentials › httpCredentials [timeout]
library/chromium/chromium.spec.ts › PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1 › serviceWorker(), and fromServiceWorker() work [timeout]
@@ -200,7 +203,6 @@ library/trace-viewer.spec.ts › should open console errors on click [fail]
library/trace-viewer.spec.ts › should pick locator in iframe [fail]
library/trace-viewer.spec.ts › should render console [fail]
library/tracing.spec.ts › should collect trace with resources, but no js [fail]
-library/tracing.spec.ts › should not include trace resources from the previous chunks [fail]
library/tracing.spec.ts › should produce screencast frames crop [fail]
library/tracing.spec.ts › should produce screencast frames fit [fail]
library/tracing.spec.ts › should produce screencast frames scale [fail]
@@ -215,6 +217,7 @@ library/video.spec.ts › screencast › should capture static page in persisten
library/video.spec.ts › screencast › should continue recording main page after popup closes [timeout]
library/video.spec.ts › screencast › should delete video [timeout]
library/video.spec.ts › screencast › should emulate an iphone [timeout]
+library/video.spec.ts › screencast › should fail when recordVideo is set [fail]
library/video.spec.ts › screencast › should expose video path [timeout]
library/video.spec.ts › screencast › should expose video path blank page [timeout]
library/video.spec.ts › screencast › should expose video path blank popup [timeout]
@@ -228,6 +231,7 @@ library/video.spec.ts › screencast › should work with old options [timeout]
library/video.spec.ts › screencast › should work with relative path for recordVideo.dir [timeout]
library/video.spec.ts › screencast › should work with video+trace [timeout]
library/video.spec.ts › screencast › should work with weird screen resolution [timeout]
+library/video.spec.ts › screencast › video.start/stop twice [timeout]
library/video.spec.ts › should saveAs video [timeout]
library/web-socket.spec.ts › should emit binary frame events [timeout]
library/web-socket.spec.ts › should emit close events [timeout]
diff --git a/tests/bidi/expectations/moz-firefox-nightly-page.txt b/tests/bidi/expectations/moz-firefox-nightly-page.txt
index ecf381593b..83d3a5df12 100644
--- a/tests/bidi/expectations/moz-firefox-nightly-page.txt
+++ b/tests/bidi/expectations/moz-firefox-nightly-page.txt
@@ -119,7 +119,6 @@ page/page-mouse.spec.ts › should always round down [fail]
page/page-mouse.spec.ts › should dblclick the div [timeout]
page/page-network-request.spec.ts › should not allow to access frame on popup main request [fail]
page/page-network-request.spec.ts › should not get preflight CORS requests when intercepting [fail]
-page/page-network-request.spec.ts › should override post data content type [fail]
page/page-network-request.spec.ts › should parse the data if content-type is application/x-www-form-urlencoded [fail]
page/page-network-request.spec.ts › should parse the data if content-type is application/x-www-form-urlencoded; charset=UTF-8 [fail]
page/page-network-request.spec.ts › should parse the json post data [fail]
@@ -134,33 +133,13 @@ page/page-network-response.spec.ts › should report all headers [fail]
page/page-network-response.spec.ts › should report if request was fromServiceWorker [fail]
page/page-network-response.spec.ts › should report multiple set-cookie headers [fail]
page/page-network-response.spec.ts › should wait until response completes [fail]
-page/page-request-continue.spec.ts › continue should delete headers on redirects [timeout]
page/page-request-continue.spec.ts › continue should drop content-length on redirects [timeout]
-page/page-request-continue.spec.ts › continue should not override cookie [timeout]
-page/page-request-continue.spec.ts › continue should not propagate cookie override to redirects [timeout]
-page/page-request-continue.spec.ts › continue should propagate headers to redirects [timeout]
-page/page-request-continue.spec.ts › post data › should compute content-length from post data [timeout]
-page/page-request-continue.spec.ts › propagate headers cross origin redirect after interception [fail]
-page/page-request-continue.spec.ts › redirect after continue should be able to delete cookie [fail]
-page/page-request-continue.spec.ts › redirected requests should report overridden headers [timeout]
-page/page-request-continue.spec.ts › should amend HTTP headers [timeout]
-page/page-request-continue.spec.ts › should continue preload link requests [timeout]
-page/page-request-continue.spec.ts › should delete header with undefined value [timeout]
-page/page-request-continue.spec.ts › should delete the origin header [fail]
-page/page-request-continue.spec.ts › should not allow to override unsafe HTTP headers [timeout]
-page/page-request-continue.spec.ts › should not forward Host header on cross-origin redirect [fail]
page/page-request-continue.spec.ts › should not throw if request was cancelled by the page [timeout]
-page/page-request-continue.spec.ts › should respect set-cookie in redirect response [timeout]
-page/page-request-continue.spec.ts › should work with Cross-Origin-Opener-Policy [fail]
-page/page-request-fallback.spec.ts › should amend HTTP headers [timeout]
-page/page-request-fallback.spec.ts › should delete header with undefined value [timeout]
page/page-request-fulfill.spec.ts › should fulfill with gzip and readback [timeout]
-page/page-request-fulfill.spec.ts › should not modify the headers sent to the server [fail]
page/page-request-fulfill.spec.ts › should not throw if request was cancelled by the page [timeout]
page/page-request-gc.spec.ts › should work [fail]
page/page-request-intercept.spec.ts › request.postData is not null when fetching FormData with a Blob [fail]
page/page-request-intercept.spec.ts › should intercept multipart/form-data request body [fail]
-page/page-route.spec.ts › should be able to remove headers [timeout]
page/page-route.spec.ts › should be abortable with custom error codes [fail]
page/page-route.spec.ts › should intercept when postData is more than 1MB [fail]
page/page-route.spec.ts › should not override cookie header [timeout]