From 2d46cd8105b2d2b2b86dcf5b1a886edb9dd01208 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 2 Sep 2020 17:30:10 -0700 Subject: [PATCH] feat(electron): automatically disable electron sandbox when run as root (#3747) --- src/server/electron/electron.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/server/electron/electron.ts b/src/server/electron/electron.ts index 822df4d3db..8341cbb0ab 100644 --- a/src/server/electron/electron.ts +++ b/src/server/electron/electron.ts @@ -15,6 +15,7 @@ */ import * as path from 'path'; +import * as os from 'os'; import { CRBrowser, CRBrowserContext } from '../chromium/crBrowser'; import { CRConnection, CRSession } from '../chromium/crConnection'; import { CRExecutionContext } from '../chromium/crExecutionContext'; @@ -149,6 +150,15 @@ export class Electron { return runAbortableTask(async progress => { let app: ElectronApplication | undefined = undefined; const electronArguments = ['--inspect=0', '--remote-debugging-port=0', '--require', path.join(__dirname, 'electronLoader.js'), ...args]; + + if (os.platform() === 'linux') { + const runningAsRoot = process.geteuid && process.geteuid() === 0; + if (runningAsRoot && electronArguments.indexOf('--no-sandbox') === -1) { + console.warn('WARNING: Playwright is being run under "root" user - disabling Electron sandbox! Run under regular user to get rid of this warning.'); + electronArguments.push('--no-sandbox'); + } + } + const { launchedProcess, gracefullyClose, kill } = await launchProcess({ executablePath, args: electronArguments,