31

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 ?

Cédric Rémond
  • 954
  • 1
  • 8
  • 20

2 Answers2

22

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.

Sergei Krupenin
  • 370
  • 2
  • 11
  • 2
    Thanks! I was able to make it work also just by setting the `CHROME_BIN` as above, and by creating the dir "C:\tmp". It's enough that "tmp" exists. Karma will create dirs named "karma-*" in "tmp". – Haprog Dec 02 '19 at 12:14
  • I tried both, but Karma is creating unique folders with differents ids each time. – EzeTeja Mar 16 '20 at 09:38
  • 4
    Creating a `C:\tmp\karma` folder did the trick for me. Thanks! – herrklaseen May 22 '20 at 07:54
  • 3
    To whom it may concern, if your source code is on another drive letter (mine was on E:), the tmp folder should be created on that drive letter (e.g E:\tmp) – Marcos Brigante Jun 28 '20 at 21:16
  • @MarcosBrigante It concerned me! Great tip, thanks much! – Spencer Easton Feb 17 '21 at 19:17
1

Now in january 2022, on WSL2, tested on debian 11/WSL under windows 11, it's "easy" :

From windows command prompt :

SET CHROME_EXECUTABLE=C:\Program Files\Google\Chrome\Application\chrome.exe

Test :

echo %CHROME_EXECUTABLE%
C:\Program Files\Google\Chrome\Application\chrome.exe

Share this Windows env variable with WSL (doc. https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/) :

set WSLENV=CHROME_EXECUTABLE/p

From Windows command prompt, enter wsl, :

wsl

Verify the env variable is ok under wsl :

echo $CHROME_EXECUTABLE
/mnt/c/Program Files/Google/Chrome/Application/chrome.exe
rach
  • 129
  • 1
  • 5