Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(bidi): fix intercepts for context.route() (#38180)
Holger Benl14212c872845
diff --git a/packages/playwright-core/src/server/bidi/bidiBrowser.ts b/packages/playwright-core/src/server/bidi/bidiBrowser.tsindex 4b4a7d906d..2ff1c281cb 100644--- a/packages/playwright-core/src/server/bidi/bidiBrowser.ts+++ b/packages/playwright-core/src/server/bidi/bidiBrowser.ts@@ -196,6 +196,7 @@ export class BidiBrowserContext extends BrowserContext {declare readonly _browser: BidiBrowser;private _originToPermissions = new Map<string, string[]>();private _initScriptIds = new Map<InitScript, string>();+ private _interceptId: bidi.Network.Intercept | undefined;constructor(browser: BidiBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) {super(browser, options, browserContextId);@@ -376,6 +377,18 @@ export class BidiBrowserContext extends BrowserContext {}async doUpdateRequestInterception(): Promise<void> {+ if (this.requestInterceptors.length > 0 && !this._interceptId) {+ const { intercept } = await this._browser._browserSession.send('network.addIntercept', {+ phases: [bidi.Network.InterceptPhase.BeforeRequestSent],+ urlPatterns: [{ type: 'pattern' }],+ });+ this._interceptId = intercept;+ }+ if (this.requestInterceptors.length === 0 && this._interceptId) {+ const intercept = this._interceptId;+ this._interceptId = undefined;+ await this._browser._browserSession.send('network.removeIntercept', { intercept });+ }}override async doUpdateDefaultViewport() {diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.tsindex 14064efb43..f3eb48f2eb 100644--- a/packages/playwright-core/src/server/bidi/bidiPage.ts+++ b/packages/playwright-core/src/server/bidi/bidiPage.ts@@ -96,7 +96,6 @@ export class BidiPage implements PageDelegate {this._onFrameAttached(this._session.sessionId, null);await Promise.all([this.updateHttpCredentials(),- this.updateRequestInterception(),// If the page is created by the Playwright client's call, some initialization// may be pending. Wait for it to complete before reporting the page as new.]);@@ -355,7 +354,7 @@ export class BidiPage implements PageDelegate {}async updateRequestInterception(): Promise<void> {- await this._networkManager.setRequestInterception(this._page.needsRequestInterception());+ await this._networkManager.setRequestInterception(this._page.requestInterceptors.length > 0);}async updateOffline() {diff --git a/tests/bidi/expectations/bidi-chromium-library.txt b/tests/bidi/expectations/bidi-chromium-library.txtindex aad83691f6..b0ef1b635c 100644--- a/tests/bidi/expectations/bidi-chromium-library.txt+++ b/tests/bidi/expectations/bidi-chromium-library.txt@@ -202,9 +202,6 @@ library/slowmo.spec.ts › slowMo › Page SlowMo setInputFiles [timeout]library/snapshotter.spec.ts › snapshots › should capture snapshot target [timeout]library/trace-viewer.spec.ts › should serve css without content-type [timeout]library/tracing.spec.ts › should collect trace with resources, but no js [timeout]-library/unroute-behavior.spec.ts › context.unroute should not wait for pending handlers to complete [timeout]-library/unroute-behavior.spec.ts › context.unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors [timeout]-library/unroute-behavior.spec.ts › context.unrouteAll should wait for pending handlers to complete [timeout]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]diff --git a/tests/bidi/expectations/moz-firefox-nightly-library.txt b/tests/bidi/expectations/moz-firefox-nightly-library.txtindex 89a4d5528d..1411a15041 100644--- a/tests/bidi/expectations/moz-firefox-nightly-library.txt+++ b/tests/bidi/expectations/moz-firefox-nightly-library.txt@@ -42,9 +42,6 @@ library/page-event-crash.spec.ts › should cancel waitForEvent when page crashelibrary/page-event-crash.spec.ts › should cancel navigation when page crashes [timeout]library/page-event-crash.spec.ts › should be able to close context when page crashes [timeout]library/popup.spec.ts › should not throw when click closes popup [timeout]-library/unroute-behavior.spec.ts › context.unroute should not wait for pending handlers to complete [timeout]-library/unroute-behavior.spec.ts › context.unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors [timeout]-library/unroute-behavior.spec.ts › context.unrouteAll should wait for pending handlers to complete [timeout]library/video.spec.ts › screencast › should be 800x450 by default [timeout]library/video.spec.ts › screencast › should be 800x600 with null viewport [timeout]library/video.spec.ts › screencast › should capture css transformation [timeout]