move persistent context logic up
This commit is contained in:
parent
eeef44455f
commit
37ab55c318
|
|
@ -40,7 +40,6 @@ import type { CallMetadata } from './instrumentation';
|
|||
import { SdkObject } from './instrumentation';
|
||||
import { ManualPromise } from '../utils/manualPromise';
|
||||
import { type ProtocolError, isProtocolError } from './protocolError';
|
||||
import type { ClientCertificatesProxy } from './socksClientCertificatesInterceptor';
|
||||
|
||||
export const kNoXServerRunningError = 'Looks like you launched a headed browser without having a XServer running.\n' +
|
||||
'Set either \'headless: true\' or use \'xvfb-run <your-playwright-app>\' before running Playwright.\n\n<3 Playwright Team';
|
||||
|
|
@ -80,9 +79,18 @@ export abstract class BrowserType extends SdkObject {
|
|||
const controller = new ProgressController(metadata, this);
|
||||
const persistent: channels.BrowserNewContextParams = { ...options };
|
||||
controller.setLogName('browser');
|
||||
|
||||
// Note: Any initial TLS requests will fail since we rely on the Page/Frames initialize which sets ignoreHTTPSErrors.
|
||||
const clientCertificatesProxy = await createClientCertificatesProxyIfNeeded(persistent);
|
||||
if (clientCertificatesProxy)
|
||||
options.proxy = persistent.proxy;
|
||||
|
||||
const browser = await controller.run(progress => {
|
||||
progress.cleanupWhenAborted(() => clientCertificatesProxy?.close());
|
||||
return this._innerLaunchWithRetries(progress, options, persistent, helper.debugProtocolLogger(), userDataDir).catch(e => { throw this._rewriteStartupLog(e); });
|
||||
}, TimeoutSettings.launchTimeout(options));
|
||||
browser._defaultContext!._clientCertificatesProxy = clientCertificatesProxy;
|
||||
|
||||
return browser._defaultContext!;
|
||||
}
|
||||
|
||||
|
|
@ -102,22 +110,8 @@ export abstract class BrowserType extends SdkObject {
|
|||
|
||||
async _innerLaunch(progress: Progress, options: types.LaunchOptions, persistent: channels.BrowserNewContextParams | undefined, protocolLogger: types.ProtocolLogger, maybeUserDataDir?: string): Promise<Browser> {
|
||||
options.proxy = options.proxy ? normalizeProxySettings(options.proxy) : undefined;
|
||||
let clientCertificatesProxy: ClientCertificatesProxy | undefined;
|
||||
if (persistent) {
|
||||
// Note: Any initial requests done by browser will not be intercepted by the client certificates proxy.
|
||||
// We rely when the Page/Frames to ignoreHTTPSErrors to bypass the certificate errors.
|
||||
clientCertificatesProxy = await createClientCertificatesProxyIfNeeded(persistent);
|
||||
options.proxy = persistent.proxy;
|
||||
}
|
||||
const browserLogsCollector = new RecentLogsCollector();
|
||||
let launchInfo;
|
||||
try {
|
||||
launchInfo = await this._launchProcess(progress, options, !!persistent, browserLogsCollector, maybeUserDataDir);
|
||||
} catch (error) {
|
||||
await clientCertificatesProxy?.close();
|
||||
throw error;
|
||||
}
|
||||
const { browserProcess, userDataDir, artifactsDir, transport } = launchInfo;
|
||||
const { browserProcess, userDataDir, artifactsDir, transport } = await this._launchProcess(progress, options, !!persistent, browserLogsCollector, maybeUserDataDir);
|
||||
if ((options as any).__testHookBeforeCreateBrowser)
|
||||
await (options as any).__testHookBeforeCreateBrowser();
|
||||
const browserOptions: BrowserOptions = {
|
||||
|
|
@ -141,16 +135,8 @@ export abstract class BrowserType extends SdkObject {
|
|||
if (persistent)
|
||||
validateBrowserContextOptions(persistent, browserOptions);
|
||||
copyTestHooks(options, browserOptions);
|
||||
let browser;
|
||||
try {
|
||||
browser = await this._connectToTransport(transport, browserOptions);
|
||||
} catch (error) {
|
||||
await clientCertificatesProxy?.close();
|
||||
throw error;
|
||||
}
|
||||
const browser = await this._connectToTransport(transport, browserOptions);
|
||||
(browser as any)._userDataDirForTest = userDataDir;
|
||||
if (persistent)
|
||||
browser._defaultContext!._clientCertificatesProxy = clientCertificatesProxy;
|
||||
// We assume no control when using custom arguments, and do not prepare the default context in that case.
|
||||
if (persistent && !options.ignoreAllDefaultArgs)
|
||||
await browser._defaultContext!._loadDefaultContext(progress);
|
||||
|
|
|
|||
Loading…
Reference in a new issue