Skip to content

Commit 7efe8ab

Browse files
committed
chore(bidi): fix intercepts for context.route()
1 parent 34a09f3 commit 7efe8ab

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export class BidiBrowserContext extends BrowserContext {
195195
declare readonly _browser: BidiBrowser;
196196
private _originToPermissions = new Map<string, string[]>();
197197
private _initScriptIds = new Map<InitScript, string>();
198+
private _interceptId: bidi.Network.Intercept | undefined;
198199

199200
constructor(browser: BidiBrowser, browserContextId: string | undefined, options: types.BrowserContextOptions) {
200201
super(browser, options, browserContextId);
@@ -375,6 +376,18 @@ export class BidiBrowserContext extends BrowserContext {
375376
}
376377

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

380393
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
]);
@@ -343,7 +342,7 @@ export class BidiPage implements PageDelegate {
343342
}
344343

345344
async updateRequestInterception(): Promise<void> {
346-
await this._networkManager.setRequestInterception(this._page.needsRequestInterception());
345+
await this._networkManager.setRequestInterception(this._page.requestInterceptors.length > 0);
347346
}
348347

349348
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)