From ba722a2580fd2267bddc980ade62317a51c995be Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 19 Aug 2022 13:48:33 -0700 Subject: [PATCH] fix(selectors): make them work in the browser reuse mode (#16691) --- packages/playwright-core/src/server/browserContext.ts | 2 ++ .../src/server/dispatchers/browserDispatcher.ts | 8 +++++--- packages/playwright-core/src/server/page.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts index 10f7fd96f2..87d3ce3672 100644 --- a/packages/playwright-core/src/server/browserContext.ts +++ b/packages/playwright-core/src/server/browserContext.ts @@ -100,6 +100,8 @@ export abstract class BrowserContext extends SdkObject { setSelectors(selectors: Selectors) { this._selectors = selectors; + for (const page of this.pages()) + page.selectors = selectors; } selectors(): Selectors { diff --git a/packages/playwright-core/src/server/dispatchers/browserDispatcher.ts b/packages/playwright-core/src/server/dispatchers/browserDispatcher.ts index 5976cb3a50..fdf7094969 100644 --- a/packages/playwright-core/src/server/dispatchers/browserDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/browserDispatcher.ts @@ -47,7 +47,7 @@ export class BrowserDispatcher extends Dispatcher { - return newContextForReuse(this._object, this._scope, params, metadata); + return newContextForReuse(this._object, this._scope, params, null, metadata); } async close(): Promise { @@ -104,7 +104,7 @@ export class ConnectedBrowserDispatcher extends Dispatcher { - return newContextForReuse(this._object, this._scope, params, metadata); + return newContextForReuse(this._object, this._scope, params, this.selectors, metadata); } async close(): Promise { @@ -141,7 +141,7 @@ export class ConnectedBrowserDispatcher extends Dispatcher { +async function newContextForReuse(browser: Browser, scope: DispatcherScope, params: channels.BrowserNewContextForReuseParams, selectors: Selectors | null, metadata: CallMetadata): Promise { const { context, needsReset } = await browser.newContextForReuse(params, metadata); if (needsReset) { const oldContextDispatcher = existingDispatcher(context); @@ -149,6 +149,8 @@ async function newContextForReuse(browser: Browser, scope: DispatcherScope, para oldContextDispatcher._dispose(); await context.resetForReuse(metadata, params); } + if (selectors) + context.setSelectors(selectors); const contextDispatcher = new BrowserContextDispatcher(scope, context); return { context: contextDispatcher }; } diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 92a741278d..c07e4aa117 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -166,7 +166,7 @@ export class Page extends SdkObject { _clientRequestInterceptor: network.RouteHandler | undefined; _serverRequestInterceptor: network.RouteHandler | undefined; _ownedContext: BrowserContext | undefined; - readonly selectors: Selectors; + selectors: Selectors; _pageIsError: Error | undefined; _video: Artifact | null = null; _opener: Page | undefined;