karma-chrome-launcher icon indicating copy to clipboard operation
karma-chrome-launcher copied to clipboard

Cannot start ChromeHeadless in Angular project, WSL

Open laneschmidt opened this issue 5 years ago • 16 comments

I'm using Windows Subsystem for Linux (Windows 10, Ubuntu 18.04 LTS). I'll list all the other pertinent versions below.

This setup is working on my Mac machine, without the flags array added to karma.conf.ts as shown below.

So far I've looked at: Headless Chrome slows tests by 10x, rebuilding yarn project using npm rebuild --update-binary, #175, #198

Expected Behaviour To launch ChromeHeadless and run the tests

Current Behaviour Running yarn test as I would normally results in this error:

02 10 2019 09:13:03.598:ERROR [launcher]: ChromeHeadless stdout:
02 10 2019 09:13:03.608:ERROR [launcher]: ChromeHeadless stderr: Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied
Failed to generate minidump.
02 10 2019 09:13:03.623:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-5419534
 21% building 99/100 modules 1 active ...ngenio/packages/web-app/src/styles.scss02 10 2019 09:13:03.699:INFO [launcher]: Trying to start ChromeHeadless again (2/2).
02 10 2019 09:13:03.702:DEBUG [launcher]: BEING_CAPTURED -> RESTARTING
02 10 2019 09:13:03.715:DEBUG [launcher]: RESTARTING -> FINISHED
 22% building 100/101 modules 1 active ...project/packages/web-app/src/styles.scss02 10 2019 09:13:03.801:DEBUG [launcher]: Restarting ChromeHeadless
02 10 2019 09:13:03.803:DEBUG [launcher]: FINISHED -> BEING_CAPTURED
02 10 2019 09:13:03.804:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-5419534
02 10 2019 09:13:03.814:DEBUG [launcher]: google-chrome --user-data-dir=/tmp/karma-5419534 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications http://localhost:9876/?id=5419534 --headless --disable-gpu --remote-debugging-port=9222
 27% building 144/145 modules 1 active ...project/packages/web-app/src/styles.scss02 10 2019 09:13:05.142:DEBUG [launcher]: Process ChromeHeadless exited with code null and signal SIGILL
02 10 2019 09:13:05.147:ERROR [launcher]: Cannot start ChromeHeadless
        Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied
Failed to generate minidump.
02 10 2019 09:13:05.159:ERROR [launcher]: ChromeHeadless stdout:
02 10 2019 09:13:05.171:ERROR [launcher]: ChromeHeadless stderr: Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied
Failed to generate minidump.
02 10 2019 09:13:05.187:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-5419534
 34% building 205/206 modules 1 active ...project/packages/web-app/src/styles.scss02 10 2019 09:13:05.679:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
02 10 2019 09:13:05.680:DEBUG [launcher]: BEING_CAPTURED -> FINISHED
02 10 2019 09:13:13.587:DEBUG [karma-server]: List of files has changed, trying to execute
02 10 2019 09:13:13.588:WARN [karma]: No captured browser, open http://localhost:9876/

and after ctrl+c...

An unhandled exception occurred: Cannot destructure property `error` of 'undefined' or 'null'.
See "/tmp/ng-GhKvib/angular-errors.log" for further details.

The file /tmp/ng-GhKvib/angular-errors.log contains An unhandled exception occurred: Cannot destructure property error of 'undefined' or 'null'..

Karma Config

// karma.conf.ts

module.exports = (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,
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage/ng2angle'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true,
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    browserDisconnectTimeout: 10000,
    browserDisconnectTolerance: 3,
    browserNoActivityTimeout: 60000,
    flags: [
      '--disable-web-security',
      '--disable-gpu',
      '--no-sandbox',
      '--disable-features=NetworkService',
      '--proxy-server="direct://"',
      '--proxy-bypass-list=*',
    ],
    singleRun: false,
    restartOnFileChange: true,
  });
};

The command that yarn test runs is ng test --karmaConfig=karma.conf.ts.

Versions

yarn=1.19.0 angular-cli=8.3.2 karma=4.1.0 karma-chrome-launcher=2.2.0 tsc=2.7.2

laneschmidt avatar Oct 02 '19 16:10 laneschmidt

I also have this issue. But apparently we are edge cases...

mfish0005 avatar Dec 25 '19 00:12 mfish0005

same issue...

eprokhor avatar Oct 06 '20 19:10 eprokhor

@eprokhor The problem is development is extremely limited in WSL2. You have to put your project's files in your Linux system's home directory(the mounted filesystem no longer works(/mnt).

I created a projects directory in my home directory: /home/mfish0005/projects. Once your project files are in there download the WSL VSCode extension. Then cd into your project's directory E.G. cd ~/projects/someAngularApp and run code . to open it in VSCode. Then you should be able to run the project. Getting the debugger to work properly is another story...

mfish0005 avatar Oct 06 '20 20:10 mfish0005

I'm having the same problem right now. Has anyone figured out any workarounds in the meantime?

JoannaFalkowska avatar Feb 02 '21 17:02 JoannaFalkowska

Hi @JoannaFalkowska I don't think there is much of a workaround due to how WSL 2 is designed. It's fundamentally different than WSL 1 because you need to work directly inside of the virtual Linux environment. If you don't everything is extremely slow and you run into issues like this one.

In other words you need to serve your app directly from the Linux environment (/home/your-project-folder) instead of the mounted filesystem (/mnt/c/your-project-folder).

I ended up reverting back to WSL 1 for now because I don't see WSL fixing this anytime soon.

mfish0005 avatar Feb 02 '21 18:02 mfish0005

@mfish0005 I reinstalled WSL 2 and tried to go the virtual Linux environment only. Turns out there is \\wsl$\ which allows you to access the Linux FS from within Windows. So you dont have to use /mnt/c/ anymore. It works very good for me now. I run IntelliJ on Windows and have set it up to load the project from \\wsl$\home\zwarag\repos\angularproject\. I also installed chrome within Windows and have VcXSrv running on Windows. It's strange but Chrome for whatever reason needs a Window to render in, even tho I start it in --headless mode.

zwarag avatar Feb 04 '21 21:02 zwarag

@zwarag Interesting. I had a similar setup going but it was so painfully slow(minimum 30 sec compile times) that it was unusable for me. Maybe they did some optimization. I should test it out and see

mfish0005 avatar Feb 04 '21 21:02 mfish0005

To make this run successfully, Please follow the procedure

Method 1: Most of the issues will be fixed and we can run ChromeHeadless if we download chromium version(debian) in wsl and install

step 1: install necessary packages

sudo apt-get update

sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4

step 2: install chromium

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo apt install ./google-chrome-stable_current_amd64.deb

If still problem persists, please follow the method 2

method 2: To run a basic Selenium UI test on any environment we need a browser and a driver to control the browser. So we've to make Windows’s Chrome browser and the chromedriver accessible from WSL.

step 1: Link Chrome browser on Windows

sudo ln -sf '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' /usr/bin/google-chrome

step 2: Link chromedriver on Windows

sudo ln -s /mnt/c/Users/username/node_modules/chromedriver/lib/chromedriver/chromedriver.exe /usr/bin/chromedriver

step 3: Change CHROME_BIN (environmental variable's default value)

export CHROME_BIN='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

If still problem persists, please follow the method 3

Method 3: This will help run puppetteer on Ubuntu, so let's install necessary packages:

sudo 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

My StackOverflow solution link

actionanand avatar Apr 28 '21 14:04 actionanand

thank you for the post @actionanand i appreciate it, hope it leads to some success!

i am no longer using WSL/Windows at all so i have not been following this issue anymore, my apologies.

laneschmidt avatar Apr 28 '21 20:04 laneschmidt

method 2: To run a basic Selenium UI test on any environment we need a browser and a driver to control the browser. So we've to make Windows’s Chrome browser and the chromedriver accessible from WSL.

step 1: Link Chrome browser on Windows

sudo ln -sf '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' /usr/bin/google-chrome

step 2: Link chromedriver on Windows

sudo ln -s /mnt/c/Users/username/node_modules/chromedriver/lib/chromedriver/chromedriver.exe /usr/bin/chromedriver

step 3: Change CHROME_BIN (environmental variable's default value)

export CHROME_BIN='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

If still problem persists, please follow the method 3

Method 2 worked for me, however, I had to not use /mnt. Instead, started with /c/ and all was well. WSL 1.

tinybigideas avatar Jul 14 '21 14:07 tinybigideas

@zwarag I resolved the issue by removing the $DISPLAY variable in my .zshrc file. Cypress depends on the Xserver which is why that variable was set. Now I am trying to figure out how I can make both cypress and chromeHeadless play together. I don't want to rely on additional configuration to keep karma happy.

tommyc38 avatar Nov 11 '21 16:11 tommyc38

To make this run successfully, Please follow the procedure

Method 1: Most of the issues will be fixed and we can run ChromeHeadless if we download chromium version(debian) in wsl and install

step 1: install necessary packages

sudo apt-get update

sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4

step 2: install chromium

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo apt install ./google-chrome-stable_current_amd64.deb

If still problem persists, please follow the method 2

method 2: To run a basic Selenium UI test on any environment we need a browser and a driver to control the browser. So we've to make Windows’s Chrome browser and the chromedriver accessible from WSL.

step 1: Link Chrome browser on Windows

sudo ln -sf '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' /usr/bin/google-chrome

step 2: Link chromedriver on Windows

sudo ln -s /mnt/c/Users/username/node_modules/chromedriver/lib/chromedriver/chromedriver.exe /usr/bin/chromedriver

step 3: Change CHROME_BIN (environmental variable's default value)

export CHROME_BIN='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

If still problem persists, please follow the method 3

Method 3: This will help run puppetteer on Ubuntu, so let's install necessary packages:

sudo 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

My StackOverflow solution link

Method 2 worked for me. I've just replaced path 'Program Files' to without (x86)

luizvicenteps avatar Sep 13 '22 18:09 luizvicenteps

Method 3: This will help run puppetteer on Ubuntu, so let's install necessary packages:

sudo 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

Thanks, method 3 worked for me (WSL 2).

ingwarbear avatar Sep 21 '22 15:09 ingwarbear

Method 2 Step 3 was the only required step for me. Steps 1 and 2 were not needed. I had to make one small change to the path, since my executable was in Program Files rather than Program Files (x86).

DerekLimble avatar Dec 13 '22 22:12 DerekLimble

To make this run successfully, Please follow the procedure Method 1: Most of the issues will be fixed and we can run ChromeHeadless if we download chromium version(debian) in wsl and install step 1: install necessary packages sudo apt-get update sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4 step 2: install chromium wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt install ./google-chrome-stable_current_amd64.deb If still problem persists, please follow the method 2 method 2: To run a basic Selenium UI test on any environment we need a browser and a driver to control the browser. So we've to make Windows’s Chrome browser and the chromedriver accessible from WSL. step 1: Link Chrome browser on Windows sudo ln -sf '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' /usr/bin/google-chrome step 2: Link chromedriver on Windows sudo ln -s /mnt/c/Users/username/node_modules/chromedriver/lib/chromedriver/chromedriver.exe /usr/bin/chromedriver step 3: Change CHROME_BIN (environmental variable's default value) export CHROME_BIN='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' If still problem persists, please follow the method 3 Method 3: This will help run puppetteer on Ubuntu, so let's install necessary packages: sudo 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 My StackOverflow solution link

Method 2 worked for me. I've just replaced path 'Program Files' to without (x86)

Happy that you found it working. Happy coding 🥇

actionanand avatar Dec 14 '22 05:12 actionanand

Two things: 0- Update your Chrome to latest stable ver 1- make sure about your local environment variable for CHROME_BIN

S-Rahemi avatar Feb 07 '23 23:02 S-Rahemi