1

I've installed chrome-driver and google-chrome in my wsl2. When I call google-chrome from wsl2, it shows this message and hangs

Starting ChromeDriver 114.0.5735.16 (7e1ff058633f5b79b1cd7479aca585ba385519d8-refs/branch-heads/5735@{#182}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

In addition, when I use

import undetected-chromedriver as uc
driver = uc.Chrome()

in python, it also just hangs.

I was able to install firefox in wsl2, call it from wsl2 and see an UI instance of it on Windows. Not sure how to do that with Chrome.

andythsu
  • 11
  • 2

1 Answers1

0

There's the bunch of settings I had to pass to chromedriver to make it work in WSL:

ChromeDriverParameterPromiseLocal = "--no-sandbox";
ChromeDriverParameterHeadless = "--headless";    
ChromeDriverParameterDisableGPU = "--disable-gpu";
ChromeDriverParameterNoDevShm = "--disable-dev-shm-usage";
ChromeDriverParameterDefaultProfile = "--profile-directory=Default";
ChromeDriverParameterUserDataDir = "--user-data-dir=~/.config/google-chrome";
ChromeDriverParameterVerbose = "--verbose";
ChromeDriverParameterDisregardIP6 = "--whitelisted-ips=";

I have no clue of Python, but that should give you an idea of what you'll need to set.

That's how to set it in C#

var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments(new List<string>
{
    // https://stackoverflow.com/q/50642308/1132334
    PdfConstants.ChromeDriverParameterPromiseLocal,
    PdfConstants.ChromeDriverParameterHeadless,
    PdfConstants.ChromeDriverParameterDisableGPU,
    PdfConstants.ChromeDriverParameterNoDevShm,
    PdfConstants.ChromeDriverParameterDefaultProfile,
    PdfConstants.ChromeDriverParameterUserDataDir,
    PdfConstants.ChromeDriverParameterVerbose,
    PdfConstants.ChromeDriverParameterDisregardIP6
});

with relevant SO link, and then

using var driver = new ChromeDriver(
    executableLocation,
    chromeOptions
);

The driver is very picky about the version. Both components are semantically versioned, and Chromium update their major version quite frequently. You need to make sure that they match, a 112.x chromedriver wouldn't drive a 114.x chrome, and the messages it throws in this case are useful but only ever shown with the --verbose flag.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77