Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma: use Windows' Chrome from WSL

Tags:

I am trying to launch karma from WSL using the Windows version of Google Chrome.

In the karma.conf.js I simply use the Chrome browser:

[...],
browsers: ['Chrome'],
[...]

And I export the CHROME_BIN environment variable like this:

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

Karma successfully find Google Chrome, and a new tab is opened at the right URL when Karma is launched. However, I get this error:

Google chrome can't read and write to its data directory /tmp/karma-XXXX

I tried starting chrome as administrator and changing the cache folder to the root of my project but it doesn't work.

I assumed there was a issue with the format of the path that Karma give to Chrome (WSL path vs Windows path).

So I create a custom karma launcher specifying the chromeDataDir:

browsers: ['WindowsChrome'],
customLaunchers: {
  WindowsChrome: {
    base: 'Chrome',
    chromeDataDir: 'D:\\'
  }
}

By doing that a I don't have the previous error, a new instance of Chrome is launched but Chrome seems unable to resolve the URL, and karma timeout. Moreover, a lot of Chrome folders are created inside my project.

Have someone already make karma work from WSL using Chrome or have any cue on what is going on ?

like image 821
Cédric Rémond Avatar asked Jan 08 '19 10:01

Cédric Rémond


People also ask

Is WSL headless?

It is not a headless or unattended install; don't run these and walk away expecting to come back to a ready to use setup.


1 Answers

I found that if you create a C:\tmp\karma folder under Windows, this error goes away, and Chrome finds and uses this folder for temp files.

You can also change the temporary folder that Chrome uses for its data by setting the TEMP environment variable like so:

export TEMP='/path/to/your/folder'

The important thing is that C:\path\to\your\folder must exist under Windows.

like image 61
Sergei Krupenin Avatar answered Nov 09 '22 06:11

Sergei Krupenin