diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.ts index 1a52a913a1..80ce04d809 100644 --- a/packages/playwright-core/src/server/electron/electron.ts +++ b/packages/playwright-core/src/server/electron/electron.ts @@ -135,12 +135,13 @@ export class Electron extends SdkObject { controller.setLogName('browser'); return controller.run(async progress => { let app: ElectronApplication | undefined = undefined; + // --remote-debugging-port=0 must be the last playwright's argument, loader.ts relies on it. const electronArguments = ['--inspect=0', '--remote-debugging-port=0', ...args]; if (os.platform() === 'linux') { const runningAsRoot = process.geteuid && process.geteuid() === 0; if (runningAsRoot && electronArguments.indexOf('--no-sandbox') === -1) - electronArguments.push('--no-sandbox'); + electronArguments.unshift('--no-sandbox'); } const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER); diff --git a/packages/playwright-core/src/server/electron/loader.ts b/packages/playwright-core/src/server/electron/loader.ts index 3180abc013..98bd92d457 100644 --- a/packages/playwright-core/src/server/electron/loader.ts +++ b/packages/playwright-core/src/server/electron/loader.ts @@ -17,9 +17,10 @@ const { app } = require('electron'); const { chromiumSwitches } = require('../chromium/chromiumSwitches'); -// [Electron, -r, loader.js, --inspect=0, --remote-debugging-port=0, ...args] -process.argv.splice(1, 4); - +// Always pass user arguments first, see https://github.com/microsoft/playwright/issues/16614 and +// https://github.com/microsoft/playwright/issues/29198. +// [Electron, -r, loader.js[, --no-sandbox>], --inspect=0, --remote-debugging-port=0, ...args] +process.argv.splice(1, process.argv.indexOf('--remote-debugging-port=0')); for (const arg of chromiumSwitches) { const match = arg.match(/--([^=]*)=?(.*)/)!;