kamilyrb
kamilyrb

Reputation: 2627

Selenium ChromeDriver gives "InitializeSandbox() called with multiple threads in process gpu-process" error

I'm trying to open a website with selenium chromedriver. I already added some arguments that I saw in other similar issues but it didn't solve problem. I've basically this code:

 String baseUrl = "https://somesite.com";
 System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
 ChromeDriverService service = ChromeDriverService.createDefaultService();
 ChromeOptions options = new ChromeOptions();
 options.addArguments("--start-maximized");
 options.addArguments("--disable-infobars");
 options.addArguments("--disable-gpu");
 options.addArguments("--disable-software-rasterizer");
 options.addArguments("no-sandbox");
 options.addArguments("headless");
 options.addArguments("--enable-native-gpu-memory-buffers");

 driver = new ChromeDriver(service, options);
 driver.get(baseUrl);

When I run the above code, chrome opens but page doesn't change. Also it gives this output:

[61263:61263:0903/005049.885829:ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.

why is this happening?

Note: My OS is ubuntu 20.04.

Upvotes: 15

Views: 31474

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193298

This error message...

ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.

...is a common Google Chrome error when trying to run it in Linux due to Chrome’s GPU usage.

First of all, System.setProperty() line accepts the key webdriver.chrome.driver and the value of the absolute path of the ChromeDriver. So instead of:

System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");

You need to:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

Outro

Generally this error can be addressed by avoiding the GPU hardware acceleration with the following flags:

  • --disable-gpu: Disables GPU hardware acceleration. If software renderer is not in place, then the GPU process won't launch
  • --disable-software-rasterizer: Disables the use of a 3D software rasterizer

Code snippet:

options.addArguments("--disable-gpu");
options.addArguments("--disable-software-rasterizer");

Upvotes: 16

Related Questions