Skip to content

Commit ea5dfdb

Browse files
authored
fix: re-write Chromium startup error with clear instructions (#3070)
This patch detects Chromium crash with a sandboxing error and re-writes the error to surface information nicely. #### Error Before: ```sh pwuser@23592d09b3bd:~/tmp$ node a.js (node:324) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.getVersion): Target closed. =========================== logs =========================== [browser] <launching> /home/pwuser/.cache/ms-playwright/chromium-790602/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disab le-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies --disable-hang-monitor --disab le-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwrig ht_chromiumdev_profile-mjSfr2 --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --no-startup-window [browser] <launched> pid=401 [browser] [0722/170825.030020:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox. [browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace() [browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace() [browser] #2 0x55ac4f853680 logging::LogMessage::~LogMessage() [browser] #3 0x55ac4df2307e content::ZygoteHostImpl::Init() [browser] #4 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize() [browser] #5 0x55ac4f45c9fa service_manager::Main() [browser] #6 0x55ac4f40c361 content::ContentMain() [browser] #7 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain() [browser] #8 0x55ac4f45b2bc headless::HeadlessShellMain() [browser] #9 0x55ac4ccc22e7 ChromeMain [browser] #10 0x7f0f3d736b97 __libc_start_main [browser] #11 0x55ac4ccc212a _start [browser] [browser] Received signal 6 [browser] #0 0x55ac4f8c7be9 base::debug::CollectStackTrace() [browser] #1 0x55ac4f841c13 base::debug::StackTrace::StackTrace() [browser] #2 0x55ac4f8c7785 base::debug::(anonymous namespace)::StackDumpSignalHandler() [browser] #3 0x7f0f437b3890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f) [browser] #4 0x7f0f3d753e97 gsignal [browser] #5 0x7f0f3d755801 abort [browser] #6 0x55ac4f8c66e5 base::debug::BreakDebugger() [browser] #7 0x55ac4f853aeb logging::LogMessage::~LogMessage() [browser] #8 0x55ac4df2307e content::ZygoteHostImpl::Init() [browser] #9 0x55ac4f40dd47 content::ContentMainRunnerImpl::Initialize() [browser] #10 0x55ac4f45c9fa service_manager::Main() [browser] #11 0x55ac4f40c361 content::ContentMain() [browser] #12 0x55ac4f45b5bd headless::(anonymous namespace)::RunContentMain() [browser] #13 0x55ac4f45b2bc headless::HeadlessShellMain() [browser] #14 0x55ac4ccc22e7 ChromeMain [browser] #15 0x7f0f3d736b97 __libc_start_main [browser] #16 0x55ac4ccc212a _start [browser] r8: 0000000000000000 r9: 00007ffd38a863b0 r10: 0000000000000008 r11: 0000000000000246 [browser] r12: 00007ffd38a87680 r13: 00007ffd38a86610 r14: 00007ffd38a87690 r15: aaaaaaaaaaaaaaaa [browser] di: 0000000000000002 si: 00007ffd38a863b0 bp: 00007ffd38a86600 bx: 00007ffd38a86e44 [browser] dx: 0000000000000000 ax: 0000000000000000 cx: 00007f0f3d753e97 sp: 00007ffd38a863b0 [browser] ip: 00007f0f3d753e97 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000 [browser] trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000 [browser] [end of stack trace] [browser] Calling _exit(1). Core file will not be generated. ============================================================ Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63 at new Promise (<anonymous>) at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16) at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31) at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:39) at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:52:38) at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:87:36) at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28) at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:60:25) at async /home/pwuser/tmp/a.js:4:19 (node:324) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:324) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ``` #### Error After: ```sh pwuser@23592d09b3bd:~/tmp$ node a.js (node:222) UnhandledPromiseRejectionWarning: browserType.launch: Chromium sandboxing failed! ================================ To workaround sandboxing issues, do either of the following: - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option ================================ Error at /home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:131:63 at new Promise (<anonymous>) at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crConnection.js:130:16) at CRSession.send (/home/pwuser/tmp/node_modules/playwright/lib/helper.js:78:31) at Function.connect (/home/pwuser/tmp/node_modules/playwright/lib/chromium/crBrowser.js:54:27) at Chromium._connectToTransport (/home/pwuser/tmp/node_modules/playwright/lib/server/chromium.js:53:38) at Chromium._innerLaunch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:89:36) at async ProgressController.run (/home/pwuser/tmp/node_modules/playwright/lib/progress.js:75:28) at async Chromium.launch (/home/pwuser/tmp/node_modules/playwright/lib/server/browserType.js:61:25) at async /home/pwuser/tmp/a.js:4:19 (node:222) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise reject ion, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:222) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ``` References #2745
1 parent 1aee8df commit ea5dfdb

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/server/browserType.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export abstract class BrowserTypeBase implements BrowserType {
9090
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
9191
options = validateLaunchOptions(options);
9292
const loggers = new Loggers(options.logger);
93-
const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, loggers, undefined), loggers.browser, TimeoutSettings.timeout(options), `browserType.launch`);
93+
const label = 'browserType.launch';
94+
const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, loggers, undefined), loggers.browser, TimeoutSettings.timeout(options), label).catch(e => { throw this._rewriteStartupError(e, label); });
9495
return browser;
9596
}
9697

@@ -99,7 +100,8 @@ export abstract class BrowserTypeBase implements BrowserType {
99100
options = validateLaunchOptions(options);
100101
const persistent = validateBrowserContextOptions(options);
101102
const loggers = new Loggers(options.logger);
102-
const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, loggers, persistent, userDataDir), loggers.browser, TimeoutSettings.timeout(options), 'browserType.launchPersistentContext');
103+
const label = 'browserType.launchPersistentContext';
104+
const browser = await runAbortableTask(progress => this._innerLaunch(progress, options, loggers, persistent, userDataDir), loggers.browser, TimeoutSettings.timeout(options), label).catch(e => { throw this._rewriteStartupError(e, label); });
103105
return browser._defaultContext!;
104106
}
105107

@@ -240,6 +242,7 @@ export abstract class BrowserTypeBase implements BrowserType {
240242
abstract _startWebSocketServer(transport: ConnectionTransport, logger: Logger, port: number): WebSocketServer;
241243
abstract _amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env;
242244
abstract _amendArguments(browserArguments: string[]): string[];
245+
abstract _rewriteStartupError(error: Error, prefix: string): Error;
243246
abstract _attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void;
244247
}
245248

src/server/chromium.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { CRBrowser } from '../chromium/crBrowser';
2222
import * as ws from 'ws';
2323
import { Env } from './processLauncher';
2424
import { kBrowserCloseMessageId } from '../chromium/crConnection';
25+
import { rewriteErrorMessage } from '../utils/stackTrace';
2526
import { BrowserTypeBase } from './browserType';
2627
import { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport';
2728
import { Logger } from '../logger';
@@ -63,6 +64,22 @@ export class Chromium extends BrowserTypeBase {
6364
return CRBrowser.connect(transport, options, devtools);
6465
}
6566

67+
_rewriteStartupError(error: Error, prefix: string): Error {
68+
// These error messages are taken from Chromium source code as of July, 2020:
69+
// https://github.com/chromium/chromium/blob/70565f67e79f79e17663ad1337dc6e63ee207ce9/content/browser/zygote_host/zygote_host_impl_linux.cc
70+
if (!error.message.includes('crbug.com/357670') && !error.message.includes('No usable sandbox!') && !error.message.includes('crbug.com/638180'))
71+
return error;
72+
return rewriteErrorMessage(error, [
73+
`${prefix}: Chromium sandboxing failed!`,
74+
`================================`,
75+
`To workaround sandboxing issues, do either of the following:`,
76+
` - (preferred): Configure environment to support sandboxing: https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md`,
77+
` - (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option`,
78+
`================================`,
79+
``,
80+
].join('\n'));
81+
}
82+
6683
_amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env {
6784
return env;
6885
}
@@ -71,6 +88,7 @@ export class Chromium extends BrowserTypeBase {
7188
// We currently only support Linux.
7289
if (os.platform() !== 'linux')
7390
return browserArguments;
91+
7492
// If there's already --no-sandbox passed in, do nothing.
7593
if (browserArguments.indexOf('--no-sandbox') !== -1)
7694
return browserArguments;

src/server/firefox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class Firefox extends BrowserTypeBase {
3939
return FFBrowser.connect(transport, options);
4040
}
4141

42+
_rewriteStartupError(error: Error, prefix: string): Error {
43+
return error;
44+
}
45+
4246
_amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[]): Env {
4347
return os.platform() === 'linux' ? {
4448
...env,

src/server/webkit.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export class WebKit extends BrowserTypeBase {
4646
return browserArguments;
4747
}
4848

49+
_rewriteStartupError(error: Error, prefix: string): Error {
50+
return error;
51+
}
52+
4953
_attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void {
5054
transport.send({method: 'Playwright.close', params: {}, id: kBrowserCloseMessageId});
5155
}

0 commit comments

Comments
 (0)