fix(selectors): make them work in the browser reuse mode (#16691)

This commit is contained in:
Pavel Feldman 2022-08-19 13:48:33 -07:00 committed by GitHub
parent e1e1035e10
commit ba722a2580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -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 {

View File

@ -47,7 +47,7 @@ export class BrowserDispatcher extends Dispatcher<Browser, channels.BrowserChann
}
async newContextForReuse(params: channels.BrowserNewContextForReuseParams, metadata: CallMetadata): Promise<channels.BrowserNewContextForReuseResult> {
return newContextForReuse(this._object, this._scope, params, metadata);
return newContextForReuse(this._object, this._scope, params, null, metadata);
}
async close(): Promise<void> {
@ -104,7 +104,7 @@ export class ConnectedBrowserDispatcher extends Dispatcher<Browser, channels.Bro
}
async newContextForReuse(params: channels.BrowserNewContextForReuseParams, metadata: CallMetadata): Promise<channels.BrowserNewContextForReuseResult> {
return newContextForReuse(this._object, this._scope, params, metadata);
return newContextForReuse(this._object, this._scope, params, this.selectors, metadata);
}
async close(): Promise<void> {
@ -141,7 +141,7 @@ export class ConnectedBrowserDispatcher extends Dispatcher<Browser, channels.Bro
}
}
async function newContextForReuse(browser: Browser, scope: DispatcherScope, params: channels.BrowserNewContextForReuseParams, metadata: CallMetadata): Promise<channels.BrowserNewContextForReuseResult> {
async function newContextForReuse(browser: Browser, scope: DispatcherScope, params: channels.BrowserNewContextForReuseParams, selectors: Selectors | null, metadata: CallMetadata): Promise<channels.BrowserNewContextForReuseResult> {
const { context, needsReset } = await browser.newContextForReuse(params, metadata);
if (needsReset) {
const oldContextDispatcher = existingDispatcher<BrowserContextDispatcher>(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 };
}

View File

@ -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;