Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Disable Chrome sandbox when unavailable #306

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion internal/karma/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ try
}
}

// Chrome on Linux uses sandboxing, which needs user namespaces to be enabled.
// This is not available on all kernels and it might be turned off even if it is available.
// Notable examples where user namespaces are not available include:
// - In Debian it is compiled-in but disabled by default.
// - The Docker daemon for Windows or OSX does not support user namespaces.
// We can detect if user namespaces are supported via /proc/sys/kernel/unprivileged_userns_clone.
// For more information see:
// https://github.com/Googlechrome/puppeteer/issues/290
// https://superuser.com/questions/1094597/enable-user-namespaces-in-debian-kernel#1122977
// https://github.com/karma-runner/karma-chrome-launcher/issues/158
// https://github.com/angular/angular/pull/24906
function supportsSandboxing() {
if (process.platform !== 'linux') {
return true;
}
try {
const res = child_process
.execSync('cat /proc/sys/kernel/unprivileged_userns_clone').toString().trim();
return res === '1';
} catch (error) { }

return false;
}

const browsers = [];
let customLaunchers = null;

Expand Down Expand Up @@ -88,7 +112,19 @@ try
} else {
process.env.CHROME_BIN = require.resolve(webTestNamedFiles['CHROMIUM']);
}
browsers.push(process.env['DISPLAY'] ? 'Chrome' : 'ChromeHeadless');
const browser = process.env['DISPLAY'] ? 'Chrome' : 'ChromeHeadless';
if (!supportsSandboxing()) {
const launcher = 'CustomChromeWithoutSandbox';
customLaunchers = {
[launcher]: {
base: browser,
flags: ['--no-sandbox']
}
};
browsers.push(launcher);
} else {
browsers.push(browser);
}
}
if (webTestNamedFiles['FIREFOX']) {
// When karma is configured to use Firefox it will look for a
Expand Down