Skip to content

Commit

Permalink
fix(electron): make sure user arguments go first (#29204)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Jan 29, 2024
1 parent 82f40d0 commit ad6e405
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/playwright-core/src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/electron/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/--([^=]*)=?(.*)/)!;
Expand Down

0 comments on commit ad6e405

Please sign in to comment.