From 813de9b563a7039d855d3be9adbe528e5ba0d553 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 24 Jan 2023 09:51:51 -0800 Subject: [PATCH] Revert "chore: respect headless option when reusing browser (#19980)" This reverts commit e674ea217f5facffc668bf7aaea890dab20d68ca. --- .../src/remote/playwrightConnection.ts | 11 ++++++++++- tests/library/debug-controller.spec.ts | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/remote/playwrightConnection.ts b/packages/playwright-core/src/remote/playwrightConnection.ts index c575d4006a202..6bd35068ad4bc 100644 --- a/packages/playwright-core/src/remote/playwrightConnection.ts +++ b/packages/playwright-core/src/remote/playwrightConnection.ts @@ -192,7 +192,10 @@ export class PlaywrightConnection { } if (!browser) { - browser = await playwright[(this._options.browserName || 'chromium') as 'chromium'].launch(serverSideCallMetadata(), this._options.launchOptions); + browser = await playwright[(this._options.browserName || 'chromium') as 'chromium'].launch(serverSideCallMetadata(), { + ...this._options.launchOptions, + headless: !!process.env.PW_DEBUG_CONTROLLER_HEADLESS, + }); browser.on(Browser.Events.Disconnected, () => { // Underlying browser did close for some reason - force disconnect the client. this.close({ code: 1001, reason: 'Browser closed' }); @@ -256,6 +259,8 @@ function launchOptionsHash(options: LaunchOptions) { if (copy[key] === defaultLaunchOptions[key]) delete copy[key]; } + for (const key of optionsThatAllowBrowserReuse) + delete copy[key]; return JSON.stringify(copy); } @@ -267,3 +272,7 @@ const defaultLaunchOptions: LaunchOptions = { headless: true, devtools: false, }; + +const optionsThatAllowBrowserReuse: (keyof LaunchOptions)[] = [ + 'headless', +]; diff --git a/tests/library/debug-controller.spec.ts b/tests/library/debug-controller.spec.ts index 843e01f1d9291..b794c8ffd1b01 100644 --- a/tests/library/debug-controller.spec.ts +++ b/tests/library/debug-controller.spec.ts @@ -30,6 +30,7 @@ type Fixtures = { const test = baseTest.extend({ wsEndpoint: async ({ }, use) => { + process.env.PW_DEBUG_CONTROLLER_HEADLESS = '1'; const server = new PlaywrightServer({ path: '/' + createGuid(), maxConnections: Number.MAX_VALUE, enableSocksProxy: false }); const wsEndpoint = await server.listen(); await use(wsEndpoint);