diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 2dac5c809c..20d91bf305 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -421,7 +421,15 @@ export class BrowserContext extends ChannelOwner private async _updateInterceptionPatterns() { const patterns = network.RouteHandler.prepareInterceptionPatterns(this._routes); await this._channel.setNetworkInterceptionPatterns({ patterns }); - await this._mockingProxy?.setInterceptionPatterns({ patterns }); + await this._updateMockingProxyInterceptionPatterns(); + } + + async _updateMockingProxyInterceptionPatterns() { + if (!this._mockingProxy) + return; + const pageRoutes = this.pages().flatMap(page => page._routes); + const patterns = network.RouteHandler.prepareInterceptionPatterns(this._routes.concat(pageRoutes)); + await this._mockingProxy.setInterceptionPatterns({ patterns }); } private async _updateWebSocketInterceptionPatterns() { diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index 88c392f3c9..2d7ecb61fd 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -568,8 +568,7 @@ export class Page extends ChannelOwner implements api.Page private async _updateInterceptionPatterns() { const patterns = RouteHandler.prepareInterceptionPatterns(this._routes); await this._channel.setNetworkInterceptionPatterns({ patterns }); - // TODO: merge this with browserContext patterns - await this._browserContext._mockingProxy?.setInterceptionPatterns({ patterns }); + await this._browserContext._updateMockingProxyInterceptionPatterns(); } private async _updateWebSocketInterceptionPatterns() {