chore: support launchPersistentContext with bidi

This commit is contained in:
Yury Semikhatsky 2024-09-16 12:07:13 -07:00
parent 21d162c945
commit e12e4f14f7
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;
} }