Skip to content

Commit

Permalink
cherry-pick(#16420): feat(driver): add reuse and navigate commands (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Aug 10, 2022
1 parent bbd3fd7 commit fdf31cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions packages/playwright-core/src/cli/driver.ts
Expand Up @@ -92,6 +92,19 @@ class ProtocolHandler {
this._playwright = playwright;
}

async resetForReuse() {
const contexts = new Set<BrowserContext>();
for (const page of this._playwright.allPages())
contexts.add(page.context());
for (const context of contexts)
await context.resetForReuse(internalMetadata, null);
}

async navigate(params: { url: string }) {
for (const p of this._playwright.allPages())
await p.mainFrame().goto(internalMetadata, params.url);
}

async setMode(params: { mode: Mode, language?: string, file?: string }) {
await gc(this._playwright);

Expand Down
8 changes: 5 additions & 3 deletions packages/playwright-core/src/server/browserContext.ts
Expand Up @@ -157,12 +157,14 @@ export abstract class BrowserContext extends SdkObject {
return JSON.stringify(paramsCopy);
}

async resetForReuse(metadata: CallMetadata, params: channels.BrowserNewContextForReuseParams) {
async resetForReuse(metadata: CallMetadata, params: channels.BrowserNewContextForReuseParams | null) {
this.setDefaultNavigationTimeout(undefined);
this.setDefaultTimeout(undefined);

for (const key of paramsThatAllowContextReuse)
(this._options as any)[key] = params[key];
if (params) {
for (const key of paramsThatAllowContextReuse)
(this._options as any)[key] = params[key];
}

await this._cancelAllRoutesInFlight();

Expand Down

0 comments on commit fdf31cd

Please sign in to comment.