添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

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

airasheed, gitpull-the-game, jimthedev, olsn, dajnz, nerumo, phuvo, oudream, DethAriel, ninjadq, and 214 more reacted with thumbs up emoji xianyuLuo, ViktorSoroka07, schoettler, Poyoman39, fpizzo20, shamonshan, edarioq, oedeven, and ryanknittel-fdx reacted with thumbs down emoji volago, nathagey, evagy, fabian-hesse-swarco, coding-lemur, leofavre, kgarber, BibbyChung, maazadeeb, laland, and 41 more reacted with hooray emoji nasikshafeek, leofavre, Timebutt, laland, nealhamilton, blazhemitrev, HZ-RotatingBlock, infinitewarp, Fzwael, Ambrance, and 33 more reacted with heart emoji ZozoZoeLi, 2b1q, calleja23, EducatedReptile, Manjuanand021, biomath-vlad, edarioq, aerialist7, jkuri, ryanknittel-fdx, and makraz reacted with rocket emoji slaveofthecode, EducatedReptile, varunramesh26, biomath-vlad, edarioq, wwiener, aerialist7, rodrigo-schamber-ac, RaimondoDev0, jkuri, and 4 more reacted with eyes emoji All reactions tariqbuilds, dhnesh, evagy, laneschmidt, qitian7, biomath-vlad, and gesinn-it-gea reacted with thumbs up emoji schoettler, rubens21, and steve-giles reacted with thumbs down emoji qitian7 reacted with hooray emoji qitian7 reacted with heart emoji qitian7 reacted with rocket emoji All reactions

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?

heigold1, V3rB0se, digibake, avijit1258, tiwanacote, cooervo, mnn888, Tammie47, hakunamatata0829, vfreestone, and 22 more reacted with thumbs up emoji willzhang reacted with thumbs down emoji willzhang and ufarruh reacted with laugh emoji willzhang reacted with hooray emoji willzhang and arashbahreini reacted with confused emoji YannPerthuis reacted with heart emoji willzhang reacted with rocket emoji willzhang reacted with eyes emoji All reactions

@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.

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
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

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/
          

^^ 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.

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, bigandy, briancyzhang, shawnmjones, yccheok, Disquse, vishesh-infiswift, pirsquare, rogerpadilla, isbasex, and 48 more reacted with thumbs up emoji victorguerra95, szahn, charliereese, cooervo, hakunamatata0829, jywarren, oskarj, eugle, jordigoyanes, michael-bc, and 3 more reacted with laugh emoji victorguerra95, Clasyc, A-Mozeak, tje3d, charliereese, ivermac, hakunamatata0829, jywarren, oskarj, chrisdamba, and 6 more reacted with hooray emoji victorguerra95, Disquse, 1ur11, tje3d, szahn, duyet, hakunamatata0829, jywarren, oskarj, flolu, and 8 more reacted with heart emoji hakunamatata0829, jywarren, oskarj, jordigoyanes, MattheuM, michael-bc, rishisoni1996, dievri, taotarodev, and j-vieira reacted with rocket emoji All reactions pushed a commit to thierrymarianne/experimenting-with-compilation-principles that referenced this issue Jul 31, 2018 プラグイン不足 - 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)

Don't forget to add --headless ChromeHeadlessNoSandbox to your test command. For me, that meant changing

ng test ${library} --browsers ChromeHeadless --watch=${watch} to

ng test ${library} --browsers ChromeHeadlessNoSandbox --watch=${watch}

It's probably obvious to you, but it took me a minute to figure that out. I hope that helps.

shobaiyer, ktamaral, dizco, squoraishee, balag3, babajidemm, Gerromie, lockie, and gema01 reacted with thumbs up emoji squoraishee, herman-rogers, and babajidemm reacted with rocket emoji All reactions

Hello I just tried the following line code and it works perfectly 💯

run this line in the terminal:
google-chrome --no-sandbox --user-data-dir

or you go here : https://stackoverflow.com/questions/12258086/how-do-i-run-google-chrome-as-root

@Zicrou or any can give some advice about How it works for you?

i will show mine config for compare

karma.config

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function(config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular-devkit/build-angular'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-jasmine-html-reporter'),
            require('karma-coverage-istanbul-reporter'),
            require('@angular-devkit/build-angular/plugins/karma')
        client: {
            clearContext: false // leave Jasmine Spec Runner output visible in browser
        coverageIstanbulReporter: {
            dir: require('path').join(__dirname, './coverage/angCICD'),
            reports: ['html', 'lcovonly', 'text-summary'],
            fixWebpackSourcePaths: true
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['ChromeHeadlessNoSandbox'],
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox']
        singleRun: false,
        restartOnFileChange: true,
        concurrency: Infinity

protractor.config

// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const puppeteer = require('puppeteer');
const { SpecReporter } = require('jasmine-spec-reporter');
 * @type { import("protractor").Config }
exports.config = {
    allScriptsTimeout: 11000,
    specs: [
        './src/**/*.e2e-spec.ts'
    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: ['--headless', '--no-sandbox'],
            binary: puppeteer.executablePath()
    directConnect: true,
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
        print: function() {}
    onPrepare() {
        require('ts-node').register({
            project: require('path').join(__dirname, './tsconfig.json')
        jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));

gitlab-ci.yml

variables:
  IMG_BUILD: node:latest
  IMG_TEST: trion/ng-cli-karma
  IMG_TESTING: alekzonder/puppeteer:latest
  IMG_TESTING_FINAL: node:8.9.1
  IMG_GITLAB_CI: juristr/angular-ci-build:1.0.0
deploy_test:
  stage: test
  image: ${IMG_BUILD}
  environment: Production
  artifacts:
    paths:
      - node_modules/
  only:
    - master
  script:
    - rm ./package-lock.json
    - apt-get update
    - apt-get install gconf-service libasound2 libatk1.0–0 libc6 libcairo2 libcups2 libdbus-1–3 libexpat1 libfontconfig1 libgcc1 libgconf-2–4 libgdk-pixbuf2.0–0 libglib2.0–0 libgtk-3–0 libnspr4 libpango-1.0–0 libpangocairo-1.0–0 libstdc++6 libx11–6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget -y
    - npm install
    - npm run test-ci

definition for npm run test-ci is:

"test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox",

and that is the error give me gitlab jobs in console

21 08 2019 17:30:16.241:WARN [karma]: No captured browser, open http://localhost:9876/
21 08 2019 17:30:16.357:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
21 08 2019 17:30:16.358:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
21 08 2019 17:30:16.361:INFO [launcher]: Starting browser ChromeHeadless
21 08 2019 17:30:17.276:ERROR [launcher]: Cannot start ChromeHeadless
	/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.276:ERROR [launcher]: ChromeHeadless stdout: 
21 08 2019 17:30:17.277:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.307:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
21 08 2019 17:30:17.358:ERROR [launcher]: Cannot start ChromeHeadless
	/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.359:ERROR [launcher]: ChromeHeadless stdout: 
21 08 2019 17:30:17.359:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.382:INFO [launcher]: Trying to start ChromeHeadless again (2/2).
21 08 2019 17:30:17.436:ERROR [launcher]: Cannot start ChromeHeadless
	/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.437:ERROR [launcher]: ChromeHeadless stdout: 
21 08 2019 17:30:17.437:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
21 08 2019 17:30:17.469:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
21 08 2019 17:30:22.314:WARN [karma]: No captured browser, open http://localhost:9876/

I have this version of puppeteer --> "puppeteer": "^1.19.0",

i am missing something?

^^ 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.

Don't forget to add --headless ChromeHeadlessNoSandbox to your test command. For me, that meant changing

ng test ${library} --browsers ChromeHeadless --watch=${watch} to

ng test ${library} --browsers ChromeHeadlessNoSandbox --watch=${watch}

It's probably obvious to you, but it took me a minute to figure that out. I hope that helps.

about this solution i have this setup

karma.config

const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();
 browsers: ['ChromeHeadlessNoSandbox'],
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox', '--headless']

in package.json apply npm run test-ci

"test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox",

gitlab-ci results

21 08 2019 20:01:29.751:WARN [karma]: No captured browser, open http://localhost:9876/
21 08 2019 20:01:29.822:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
21 08 2019 20:01:29.822:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
21 08 2019 20:01:29.849:INFO [launcher]: Starting browser ChromeHeadless
21 08 2019 20:01:30.732:ERROR [launcher]: Cannot start ChromeHeadless
	/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
          

That results in a SIGSEGV for me, although the tests appear to pass.

01 05 2020 15:15:01.930:INFO [karma-server]: Karma v5.0.2 server started at http://0.0.0.0:9876/
01 05 2020 15:15:01.932:INFO [launcher]: Launching browsers ChromeNoSandbox with concurrency unlimited
01 05 2020 15:15:01.951:INFO [launcher]: Starting browser ChromeHeadless
01 05 2020 15:15:02.241:INFO [Chrome Headless 81.0.4044.129 (Mac OS 10.14.6)]: Connected on socket PylVnfHy8jmDMhm2AAAA with id 97738507
Chrome Headless 81.0.4044.129 (Mac OS 10.14.6): Executed 13 of 14 (skipped 1) SUCCESS (0.01 secs / 0.042 secs)
TOTAL: 13 SUCCESS
error Command failed with signal "SIGSEGV".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed: /Users/lpender/.yvm/versions/v1.22.4/bin/yarn.js test --browsers ChromeNoSandbox
          

My karma.conf.js looks like
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true

reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
  customLaunchers:{
    ChromeHeadlessNoSandbox:{
      base: 'ChromeHeadless',
      flags: ['--no-sandbox']
singleRun: false

but after running npm test
getting error as

Disconnected (0 times) , because no message in 30000 ms.
Chrome Headless 92.0.4515.131 (Windows 10) ERROR
Disconnected , because no message in 30000 ms.

Chrome Headless 92.0.4515.131 (Windows 10) ERROR
Disconnected , because no message in 30000 ms.

npm ERR! Test failed. See above for more details.

i solved after see this videos https://youtu.be/tc379GTTgys

100% problem has been fixed :) ..

THANKS BRO FOR THIS VIDEO MY PROBLEM SOLVED;
<<<print("thanks for this")