Skip to content

Commit 47e30f0

Browse files
authored
feat: introduce chromiumSandbox launch option (#3067)
The option is intended to be used instead of the `--no-sandbox` argument that is accepted exclusively by Chromium and crashes WebKit. References #2745
1 parent af20d27 commit 47e30f0

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

docs/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,6 +3983,7 @@ This methods attaches Playwright to an existing browser instance.
39833983
- `username` <[string]> Optional username to use if HTTP proxy requires authentication.
39843984
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
39853985
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
3986+
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
39863987
- `firefoxUserPrefs` <[Object]> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
39873988
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
39883989
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
@@ -4024,6 +4025,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
40244025
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
40254026
- `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
40264027
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4028+
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
40274029
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
40284030
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.
40294031
- `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
@@ -4072,6 +4074,7 @@ Launches browser that uses persistent storage located at `userDataDir` and retur
40724074
- `username` <[string]> Optional username to use if HTTP proxy requires authentication.
40734075
- `password` <[string]> Optional password to use if HTTP proxy requires authentication.
40744076
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this folder. Otherwise, temporary folder is created and is deleted when browser is closed.
4077+
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
40754078
- `firefoxUserPrefs` <[Object]> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
40764079
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
40774080
- `handleSIGTERM` <[boolean]> Close the browser process on SIGTERM. Defaults to `true`.

docs/ci.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ Bitbucket Pipelines can use public [Docker images as build environments](https:/
178178
image: mcr.microsoft.com/playwright:bionic
179179
```
180180

181-
While the Docker image supports sandboxing for Chromium, it does not work in the Bitbucket Pipelines environment. To launch Chromium on Bitbucket Pipelines, use the `--no-sandbox` launch argument.
181+
While the Docker image supports sandboxing for Chromium, it does not work in the Bitbucket Pipelines environment. To launch Chromium on Bitbucket Pipelines, use the `chromiumSandbox: false` launch argument.
182182

183183
```js
184184
const { chromium } = require('playwright');
185-
const browser = await chromium.launch({ args: ['--no-sandbox'] });
185+
const browser = await chromium.launch({ chromiumSandbox: false });
186186
```
187187

188188
### GitLab CI

docs/troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ the host should be configured first. If there's no good sandbox for Chrome to us
140140
with the error `No usable sandbox!`.
141141

142142
If you **absolutely trust** the content you open in Chrome, you can launch Chrome
143-
with the `--no-sandbox` argument:
143+
with the `chromiumSandbox: false` option:
144144

145145
```js
146-
const browser = await playwright.chromium.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
146+
const browser = await playwright.chromium.launch({ chromiumSandbox: false });
147147
```
148148

149149
> **NOTE**: Running without a sandbox is **strongly discouraged**. Consider configuring a sandbox instead.

src/server/chromium.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export class Chromium extends BrowserTypeBase {
115115
'--mute-audio'
116116
);
117117
}
118+
if (options.chromiumSandbox === false)
119+
chromeArguments.push('--no-sandbox');
118120
if (proxy) {
119121
const proxyURL = new URL(proxy.server);
120122
const isSocks = proxyURL.protocol === 'socks5:';

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export type LaunchOptionsBase = {
295295
devtools?: boolean,
296296
proxy?: ProxySettings,
297297
downloadsPath?: string,
298+
chromiumSandbox?: boolean,
298299
};
299300

300301
export type LaunchOptions = LaunchOptionsBase & { slowMo?: number };

utils/generate_types/test/test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ playwright.chromium.launch().then(async browser => {
194194
// Example with launch options
195195
(async () => {
196196
const browser = await playwright.chromium.launch({
197-
args: [
198-
'--no-sandbox',
199-
'--disable-setuid-sandbox',
200-
],
197+
chromiumSandbox: false,
201198
handleSIGINT: true,
202199
handleSIGHUP: true,
203200
handleSIGTERM: true,

0 commit comments

Comments
 (0)