From 7c598a705a61158eff413e94c65f3037955ab948 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 24 Jan 2025 13:17:43 +0100 Subject: [PATCH] move route._context --- packages/playwright-core/src/client/browserContext.ts | 7 +++++-- packages/playwright-core/src/client/page.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 0b5220d8f0..c2ca79d70f 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -93,7 +93,11 @@ export class BrowserContext extends ChannelOwner this._channel.on('bindingCall', ({ binding }) => this._onBinding(BindingCall.from(binding))); this._channel.on('close', () => this._onClose()); this._channel.on('page', ({ page }) => this._onPage(Page.from(page))); - this._channel.on('route', ({ route }) => this._onRoute(network.Route.from(route))); + this._channel.on('route', params => { + const route = network.Route.from(params.route); + route._context = this.request; + this._onRoute(route); + }); this._channel.on('webSocketRoute', ({ webSocketRoute }) => this._onWebSocketRoute(network.WebSocketRoute.from(webSocketRoute))); this._channel.on('backgroundPage', ({ page }) => { const backgroundPage = Page.from(page); @@ -201,7 +205,6 @@ export class BrowserContext extends ChannelOwner } async _onRoute(route: network.Route) { - route._context = this.request; const page = route.request()._safePage(); const routeHandlers = this._routes.slice(); for (const routeHandler of routeHandlers) { diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index 960ea72bb5..9521478406 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -138,7 +138,11 @@ export class Page extends ChannelOwner implements api.Page this._channel.on('frameAttached', ({ frame }) => this._onFrameAttached(Frame.from(frame))); this._channel.on('frameDetached', ({ frame }) => this._onFrameDetached(Frame.from(frame))); this._channel.on('locatorHandlerTriggered', ({ uid }) => this._onLocatorHandlerTriggered(uid)); - this._channel.on('route', ({ route }) => this._onRoute(Route.from(route))); + this._channel.on('route', params => { + const route = Route.from(params.route); + route._context = this.context().request; + this._onRoute(route); + }); this._channel.on('webSocketRoute', ({ webSocketRoute }) => this._onWebSocketRoute(WebSocketRoute.from(webSocketRoute))); this._channel.on('video', ({ artifact }) => { const artifactObject = Artifact.from(artifact); @@ -180,7 +184,6 @@ export class Page extends ChannelOwner implements api.Page } async _onRoute(route: Route) { - route._context = this.context().request; const routeHandlers = this._routes.slice(); for (const routeHandler of routeHandlers) { // If the page was closed we stall all requests right away.