Skip to content

Commit d5f61b5

Browse files
committed
chore(bidi): fix intercepts for context.route()
1 parent 55eddb8 commit d5f61b5

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/playwright-core/src/server/bidi/bidiBrowser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class BidiBrowserContext extends BrowserContext {
191191
declare readonly _browser: BidiBrowser;
192192
private _originToPermissions = new Map<string, string[]>();
193193
private _initScriptIds = new Map<InitScript, string>();
194+
private _interceptIdPromise: Promise<bidi.Network.Intercept> | undefined;
194195

195196
constructor(browser: BidiBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) {
196197
super(browser, options, browserContextId);
@@ -373,6 +374,19 @@ export class BidiBrowserContext extends BrowserContext {
373374
}
374375

375376
async doUpdateRequestInterception(): Promise<void> {
377+
if (this.requestInterceptors.length > 0 && !this._interceptIdPromise) {
378+
this._interceptIdPromise = this._browser._browserSession.send('network.addIntercept', {
379+
phases: [bidi.Network.InterceptPhase.BeforeRequestSent],
380+
urlPatterns: [{ type: 'pattern' }],
381+
}).then(({ intercept }) => intercept);
382+
}
383+
if (this.requestInterceptors.length === 0 && this._interceptIdPromise) {
384+
const interceptIdPromise = this._interceptIdPromise;
385+
this._interceptIdPromise = undefined;
386+
await this._browser._browserSession.send('network.removeIntercept', {
387+
intercept: await interceptIdPromise
388+
});
389+
}
376390
}
377391

378392
override async doUpdateDefaultViewport() {

packages/playwright-core/src/server/bidi/bidiPage.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export class BidiPage implements PageDelegate {
9595
this._onFrameAttached(this._session.sessionId, null);
9696
await Promise.all([
9797
this.updateHttpCredentials(),
98-
this.updateRequestInterception(),
9998
// If the page is created by the Playwright client's call, some initialization
10099
// may be pending. Wait for it to complete before reporting the page as new.
101100
]);
@@ -345,7 +344,7 @@ export class BidiPage implements PageDelegate {
345344
}
346345

347346
async updateRequestInterception(): Promise<void> {
348-
await this._networkManager.setRequestInterception(this._page.needsRequestInterception());
347+
await this._networkManager.setRequestInterception(this._page.requestInterceptors.length > 0);
349348
}
350349

351350
async updateOffline() {

tests/bidi/expectations/bidi-chromium-library.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ library/slowmo.spec.ts › slowMo › Page SlowMo setInputFiles [timeout]
202202
library/snapshotter.spec.ts › snapshots › should capture snapshot target [timeout]
203203
library/trace-viewer.spec.ts › should serve css without content-type [timeout]
204204
library/tracing.spec.ts › should collect trace with resources, but no js [timeout]
205-
library/unroute-behavior.spec.ts › context.unroute should not wait for pending handlers to complete [timeout]
206-
library/unroute-behavior.spec.ts › context.unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors [timeout]
207-
library/unroute-behavior.spec.ts › context.unrouteAll should wait for pending handlers to complete [timeout]
208205
library/video.spec.ts › screencast › should expose video path [timeout]
209206
library/video.spec.ts › screencast › should expose video path blank page [timeout]
210207
library/video.spec.ts › screencast › should expose video path blank popup [timeout]

tests/bidi/expectations/moz-firefox-nightly-library.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ library/page-event-crash.spec.ts › should cancel waitForEvent when page crashe
4343
library/page-event-crash.spec.ts › should cancel navigation when page crashes [timeout]
4444
library/page-event-crash.spec.ts › should be able to close context when page crashes [timeout]
4545
library/popup.spec.ts › should not throw when click closes popup [timeout]
46-
library/unroute-behavior.spec.ts › context.unroute should not wait for pending handlers to complete [timeout]
47-
library/unroute-behavior.spec.ts › context.unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors [timeout]
48-
library/unroute-behavior.spec.ts › context.unrouteAll should wait for pending handlers to complete [timeout]
4946
library/video.spec.ts › screencast › should be 800x450 by default [timeout]
5047
library/video.spec.ts › screencast › should be 800x600 with null viewport [timeout]
5148
library/video.spec.ts › screencast › should capture css transformation [timeout]

0 commit comments

Comments
 (0)