New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChromeHeadless can't run as root with --no-sandbox anymore #158

Open
boboldehampsink opened this Issue Oct 25, 2017 · 15 comments

Comments

Projects
None yet
@boboldehampsink
Copy link

boboldehampsink commented Oct 25, 2017

After updating to Chrome 62 and Chromedriver 2.33, I get the following error when running karma tests with ChromeHeadless:

  | 25 10 2017 08:47:40.197:ERROR [launcher]: Cannot start ChromeHeadless
  | [1025/084740.006078:ERROR:zygote_host_impl_linux.cc(88)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

This is in Docker running Ubuntu 16

@boboldehampsink

This comment has been minimized.

Copy link

boboldehampsink commented Oct 25, 2017

Workaround:

    browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },
@afaqurk

This comment has been minimized.

Copy link

afaqurk commented Oct 25, 2017

@boboldehampsink Is it assumed that your actual configuration also has --headless and --remote-debugging=9222 in the flags array?

@boboldehampsink

This comment has been minimized.

Copy link

boboldehampsink commented Oct 25, 2017

When specifying the browser as ChromeHeadless this is automatically added, yes.

@afaqurk

This comment has been minimized.

Copy link

afaqurk commented Oct 25, 2017

This worked for us. Thanks, @boboldehampsink

@sebastian-burdun

This comment has been minimized.

Copy link

sebastian-burdun commented Nov 28, 2017

Worked for me too. Thanks.

gsalaun1 added a commit to gsalaun1/tech-radar-jhipster that referenced this issue Dec 3, 2017

@germs12

This comment has been minimized.

Copy link

germs12 commented Dec 19, 2017

Worked for me too. Thanks guys!

Keywords: CodeBuild, Karma, Chrome

@myluckagain

This comment has been minimized.

Copy link

myluckagain commented Dec 23, 2017

boboldehampsink, sorry, but where should this workaround be written? Is it about docker?

@boboldehampsink

This comment has been minimized.

Copy link

boboldehampsink commented Dec 24, 2017

In karma config

@DragonRus

This comment has been minimized.

Copy link

DragonRus commented Dec 31, 2017

Sorry for the rookie question: and where should I put this text?

browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},

Where is this karma config?

@metalex9

This comment has been minimized.

Copy link

metalex9 commented Jan 2, 2018

@DragonRus By default, most projects have Karma configuration stored in a file named "karma.conf.js." However, that is just the default; the configuration file could be named anything and passed to Karma like this: karma start some-karma-config.js.

If your project doesn't have a configuration file, you can generate it by running karma init from a command line. See the Karma documentation.

@oliversalzburg

This comment has been minimized.

Copy link

oliversalzburg commented Mar 22, 2018

I was not aware of the ability to define custom launchers. I would consider it very helpful if this was added to the README.

openstack-gerrit pushed a commit to openstack/openstack-health that referenced this issue Mar 30, 2018

Add support for HeadlessChrome in karma
Motivation for this change:
  As a tester, I want to execute npm unit tests in a headless
  chrome environment.

Notes on implementation:
  * Running headless chrome requires verion chrome 59 or greater[1]
  * --no-sandbox flag is a workaround for running as root[2]
  * HeadlessChrome base was added in karma-chrome-launcher v2.1.0[3]
    - upgrading to this package caused a CHROME_BIN not set error[4].
      Setting CHROME_BIN to chromium-browser fixes the issue.
  * Using Chrome without the upgraded packages causes an error during
    the coverage report generation
    - TypeError: Cannot read property 'start' of undefined[5]

[1] https://github.com/karma-runner/karma-chrome-launcher#available-browsers
[2] karma-runner/karma-chrome-launcher#158
[3] https://github.com/karma-runner/karma-chrome-launcher/releases/tag/v2.1.0
[4] http://paste.openstack.org/show/715433/
[5] https://review.openstack.org/#/c/456556/9

Change-Id: I907708d73b5fe5345f3a56d8d638c51e7d3aa6f7

wmfgerrit pushed a commit to wikimedia/oojs that referenced this issue Apr 3, 2018

build: Set --no-sandbox in Chrome for Travis
The Travis CI build for wikimedia/oojs has been failing since
January 2018 due to an incompatibility between Travis' Docker
configuration, and Chrome's sandboxing feature.

The --no-sandbox flag is a documented workaround. The alternative
being to switch to sudo-enabled builds, but those are slower, and
we don't need sandboxing within Travis CI docker builds anyway.

https://docs.travis-ci.com/user/chrome
karma-runner/karma-chrome-launcher#158

Also:
* Rename `saucelabs.browsers.js` to `karma.browsers.js`.
* Rename 'qunit karma:other' to 'qunit karma:firefox'.

Change-Id: I3b688c9ef12e0c156bb9908d61d959adbc41276f
@AlexanderKozhevin

This comment has been minimized.

Copy link

AlexanderKozhevin commented May 2, 2018

I keep getting smth like this in bitbucket pipeline.

02 05 2018 19:40:16.221:WARN [karma]: No captured browser, open http://localhost:9876/
02 05 2018 19:40:16.230:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
02 05 2018 19:40:16.230:INFO [launcher]: Launching browser Chrome with unlimited concurrency
02 05 2018 19:40:16.236:INFO [launcher]: Starting browser Chrome
02 05 2018 19:40:16.656:ERROR [launcher]: Cannot start Chrome
	[79:79:0502/194016.598825:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:16.656:ERROR [launcher]: Chrome stdout: 
02 05 2018 19:40:16.656:ERROR [launcher]: Chrome stderr: [79:79:0502/194016.598825:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:16.676:INFO [launcher]: Trying to start Chrome again (1/2).
02 05 2018 19:40:16.883:ERROR [launcher]: Cannot start Chrome
	[90:90:0502/194016.759919:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:16.883:ERROR [launcher]: Chrome stdout: 
02 05 2018 19:40:16.883:ERROR [launcher]: Chrome stderr: [90:90:0502/194016.759919:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:16.919:INFO [launcher]: Trying to start Chrome again (2/2).
02 05 2018 19:40:17.145:ERROR [launcher]: Cannot start Chrome
	[101:101:0502/194017.008599:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:17.145:ERROR [launcher]: Chrome stdout: 
02 05 2018 19:40:17.145:ERROR [launcher]: Chrome stderr: [101:101:0502/194017.008599:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
02 05 2018 19:40:17.152:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
02 05 2018 19:40:23.683:WARN [karma]: No captured browser, open http://localhost:9876/
@marksyzm

This comment has been minimized.

Copy link

marksyzm commented May 8, 2018

^^ I had something like that in Jenkins. Turned out I had to set the --browsers flag in the command as it was still defaulting to plain headless Chrome without the --no-sandbox flag. Here's one example of what I used: yarn test --single-run --no-progress --browsers Chrome_without_security

Where Chrome_without_security was set up as this:

module.exports = function (config) {
  process.env.CHROME_BIN = require('puppeteer').executablePath()

  config.set({

    // You may use 'ChromeCanary', 'Chromium' or any other supported browser
    browsers: ['Chrome_without_security'], 
    // you can define custom flags
    customLaunchers: {
      Chrome_without_security: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    }
  });
};

Puppeteer is there to handle any missing Chrome package, of course.

@yuri-wisestamp

This comment has been minimized.

Copy link

yuri-wisestamp commented Jun 13, 2018

If you're running Puppeteer directly from Node code, you can provide this flag as follows:
const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});

@victorguerra95

This comment has been minimized.

Copy link

victorguerra95 commented Jun 20, 2018

Thanks! @yuri-wisestamp

thierrymarianne added a commit to thierrymarianne/learning-compilation-principles that referenced this issue Jul 31, 2018

oki2a24 added a commit to oki2a24/kanban-app that referenced this issue Jan 20, 2019

fix: 8.8.7 単体テストユーティリティの導入。Vue Test Utilsによる効率化。この状態で動かないのを修正する
エラーメッセージを検索して、対処していった。

プラグイン不足

- javascript - Vue-test-utils can't find `Set()`: ReferenceError: Can't find variable: Set - Stack Overflow https://stackoverflow.com/questions/53764988/vue-test-utils-cant-find-set-referenceerror-cant-find-variable-set
- javascript - karma plugin dependencies not being found - Stack Overflow https://stackoverflow.com/questions/32425580/karma-plugin-dependencies-not-being-found
- Error: No provider for "framework:mocha"! (Resolving: framework:mocha) · Issue #42 · karma-runner/karma-mocha karma-runner/karma-mocha#42 (comment)
- Reporter plugins not working with karma 1.1.1? · Issue #2246 · karma-runner/karma karma-runner/karma#2246 (comment)
- "Can not load "coverage", it is not registered!" error when running · Issue #59 · karma-runner/karma-coverage karma-runner/karma-coverage#59 (comment)

Chrome Headless を使用するために Chromium インストールとパスを設定
apt-get update
apt-get install chromium
hromium --version
export CHROME_BIN=/usr/bin/chromium

- [launcher]: No binary for Chrome browser on your platform. · Issue #62 · karma-runner/karma-chrome-launcher karma-runner/karma-chrome-launcher#62
- Dockerを使ってHeadless Chromeを動かしてみる - Qiita https://qiita.com/dd511805/items/dfe03c5486bf1421875a
- Puppeteer をDockerコンテナで利用する - Qiita https://qiita.com/HeRo/items/9be64b559692e12cc109

Chrome Headless の起動オプション設定

- ChromeHeadless can't run as root with --no-sandbox anymore · Issue #158 · karma-runner/karma-chrome-launcher karma-runner/karma-chrome-launcher#158 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment