From ea963a8e86d60f456ca889ef98300934e4e5fc3c Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 5 May 2023 15:01:17 -0700 Subject: [PATCH] cherry-pick(#22855): fix(server): explicit allowlist for launch options (#22857) Some options, usually paths, do not make sense when running remotely. --- .../src/remote/playwrightConnection.ts | 16 ++++++++++++++++ tests/library/browsertype-connect.spec.ts | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/playwright-core/src/remote/playwrightConnection.ts b/packages/playwright-core/src/remote/playwrightConnection.ts index ce27a99af3..a8dc6ef3e3 100644 --- a/packages/playwright-core/src/remote/playwrightConnection.ts +++ b/packages/playwright-core/src/remote/playwrightConnection.ts @@ -57,6 +57,7 @@ export class PlaywrightConnection { this._ws = ws; this._preLaunched = preLaunched; this._options = options; + options.launchOptions = filterLaunchOptions(options.launchOptions); if (clientType === 'reuse-browser' || clientType === 'pre-launched-browser-or-android') assert(preLaunched.playwright); if (clientType === 'pre-launched-browser-or-android') @@ -271,6 +272,21 @@ function launchOptionsHash(options: LaunchOptions) { return JSON.stringify(copy); } +function filterLaunchOptions(options: LaunchOptions) { + return { + channel: options.channel, + args: options.args, + ignoreAllDefaultArgs: options.ignoreAllDefaultArgs, + ignoreDefaultArgs: options.ignoreDefaultArgs, + timeout: options.timeout, + headless: options.headless, + proxy: options.proxy, + chromiumSandbox: options.chromiumSandbox, + firefoxUserPrefs: options.firefoxUserPrefs, + slowMo: options.slowMo, + }; +} + const defaultLaunchOptions: LaunchOptions = { ignoreAllDefaultArgs: false, handleSIGINT: false, diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.ts index 113a1c200c..e9577cde29 100644 --- a/tests/library/browsertype-connect.spec.ts +++ b/tests/library/browsertype-connect.spec.ts @@ -576,6 +576,19 @@ for (const kind of ['launchServer', 'run-server'] as const) { expect(entry.request.url).toBe(server.EMPTY_PAGE); }); + test('should filter launch options', async ({ connect, startRemoteServer, server, browserType }, testInfo) => { + const tracesDir = testInfo.outputPath('traces'); + const oldTracesDir = (browserType as any)._defaultLaunchOptions.tracesDir; + (browserType as any)._defaultLaunchOptions.tracesDir = tracesDir; + const remoteServer = await startRemoteServer(kind); + const browser = await connect(remoteServer.wsEndpoint()); + const page = await browser.newPage(); + await page.goto(server.EMPTY_PAGE); + await browser.close(); + (browserType as any)._defaultLaunchOptions.tracesDir = oldTracesDir; + expect(fs.existsSync(tracesDir)).toBe(false); + }); + test('should record trace with sources', async ({ connect, startRemoteServer, server, trace }, testInfo) => { test.skip(trace === 'on'); const remoteServer = await startRemoteServer(kind);