Skip to content

Commit 80773fa

Browse files
authored
fix: disable chromium sandbox by default (#4090)
Certain environments, e.g. Azure Pipelines, override default user inside container with a custom one, whereas fail to pass proper seccomp profile for the docker image. As a result, chromium sandboxing fails. To ease life of devops deploying tests in various CI's, this patch disables Chromium sandbox by default. References #4084
1 parent d6a198a commit 80773fa

File tree

5 files changed

+3
-27
lines changed

5 files changed

+3
-27
lines changed

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4206,7 +4206,7 @@ This methods attaches Playwright to an existing browser instance.
42064206
- `username` <[string]> Optional username to use if HTTP proxy requires authentication.
42074207
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
42084208
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4209-
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
4209+
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `false`.
42104210
- `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
42114211
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
42124212
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.

src/server/browserType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export abstract class BrowserType {
169169
let browserProcess: BrowserProcess | undefined = undefined;
170170
const { launchedProcess, gracefullyClose, kill } = await launchProcess({
171171
executablePath: executable,
172-
args: this._amendArguments(browserArguments),
172+
args: browserArguments,
173173
env: this._amendEnvironment(env, userDataDir, executable, browserArguments),
174174
handleSIGINT,
175175
handleSIGTERM,
@@ -212,7 +212,6 @@ export abstract class BrowserType {
212212
abstract _defaultArgs(options: types.LaunchOptions, isPersistent: boolean, userDataDir: string): string[];
213213
abstract _connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<Browser>;
214214
abstract _amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env;
215-
abstract _amendArguments(browserArguments: string[]): string[];
216215
abstract _rewriteStartupError(error: Error): Error;
217216
abstract _attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void;
218217
}

src/server/chromium/chromium.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import * as path from 'path';
19-
import * as os from 'os';
2019
import { CRBrowser } from './crBrowser';
2120
import { Env } from '../processLauncher';
2221
import { kBrowserCloseMessageId } from './crConnection';
@@ -80,20 +79,6 @@ export class Chromium extends BrowserType {
8079
return env;
8180
}
8281

83-
_amendArguments(browserArguments: string[]): string[] {
84-
// We currently only support Linux.
85-
if (os.platform() !== 'linux')
86-
return browserArguments;
87-
88-
// If there's already --no-sandbox passed in, do nothing.
89-
if (browserArguments.indexOf('--no-sandbox') !== -1)
90-
return browserArguments;
91-
const runningAsRoot = process.geteuid && process.geteuid() === 0;
92-
if (runningAsRoot)
93-
return ['--no-sandbox', ...browserArguments];
94-
return browserArguments;
95-
}
96-
9782
_attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void {
9883
const message: ProtocolRequest = { method: 'Browser.close', id: kBrowserCloseMessageId, params: {} };
9984
transport.send(message);
@@ -124,7 +109,7 @@ export class Chromium extends BrowserType {
124109
'--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4',
125110
);
126111
}
127-
if (options.chromiumSandbox === false)
112+
if (options.chromiumSandbox !== true)
128113
chromeArguments.push('--no-sandbox');
129114
if (proxy) {
130115
const proxyURL = new URL(proxy.server);

src/server/firefox/firefox.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export class Firefox extends BrowserType {
4949
} : env;
5050
}
5151

52-
_amendArguments(browserArguments: string[]): string[] {
53-
return browserArguments;
54-
}
55-
5652
_attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void {
5753
const message = { method: 'Browser.close', params: {}, id: kBrowserCloseMessageId };
5854
transport.send(message);

src/server/webkit/webkit.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ export class WebKit extends BrowserType {
3838
return { ...env, CURL_COOKIE_JAR_PATH: path.join(userDataDir, 'cookiejar.db') };
3939
}
4040

41-
_amendArguments(browserArguments: string[]): string[] {
42-
return browserArguments;
43-
}
44-
4541
_rewriteStartupError(error: Error): Error {
4642
return error;
4743
}

0 commit comments

Comments
 (0)