chore: support launchPersistentContext with bidi (#32641)

This commit is contained in:
Yury Semikhatsky 2024-09-16 17:31:26 -07:00 committed by GitHub
parent 6dbde62a6b
commit 2a347b5494
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 9 deletions

View file

@ -94,6 +94,14 @@ export class BidiBrowser extends Browser {
'script', 'script',
], ],
}); });
if (options.persistent) {
browser._defaultContext = new BidiBrowserContext(browser, undefined, options.persistent);
await (browser._defaultContext as BidiBrowserContext)._initialize();
// Create default page as we cannot get access to the existing one.
const pageDelegate = await browser._defaultContext.newPageDelegate();
await pageDelegate.pageOrError();
}
return browser; return browser;
} }
@ -294,10 +302,11 @@ export class BidiBrowserContext extends BrowserContext {
} }
async doClose(reason: string | undefined) { async doClose(reason: string | undefined) {
// TODO: implement for persistent context if (!this._browserContextId) {
if (!this._browserContextId) // Closing persistent context should close the browser.
await this._browser.close({ reason });
return; return;
}
await this._browser._browserSession.send('browser.removeUserContext', { await this._browser._browserSession.send('browser.removeUserContext', {
userContext: this._browserContextId userContext: this._browserContextId
}); });

View file

@ -76,12 +76,6 @@ export class BidiFirefox extends BrowserType {
firefoxArguments.push('--foreground'); firefoxArguments.push('--foreground');
firefoxArguments.push(`--profile`, userDataDir); firefoxArguments.push(`--profile`, userDataDir);
firefoxArguments.push(...args); firefoxArguments.push(...args);
// TODO: make ephemeral context work without this argument.
firefoxArguments.push('about:blank');
// if (isPersistent)
// firefoxArguments.push('about:blank');
// else
// firefoxArguments.push('-silent');
return firefoxArguments; return firefoxArguments;
} }