Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headless chrome + ignore-certificate-errors

I need to get headless chrome to ignore certificate errors. The option is ignored when running in headless mode, and the driver returns empty html body tags when navigating to an https resource.

<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html> 

This is how I am configuring my chrome driver.

 ChromeOptions chromeOptions = new ChromeOptions();  chromeOptions.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");   DesiredCapabilities cap=DesiredCapabilities.chrome();   cap.setCapability(ChromeOptions.CAPABILITY, chromeOptions);  cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);  cap.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);  chromeHeadlessDriver = new ChromeDriver(cap); 

This thread confirms that --ignore-certificate-errors is ignored in headless mode.

They mention about devtool protocol.

Is it something I can invoke from java? Are there any other alternatives?

like image 694
miklesw Avatar asked Aug 04 '17 15:08

miklesw


People also ask

How do I ignore certificate errors in Chrome?

You can tell Chrome to ignore all SSL certificate errors by passing the following at the command line at launch. If you're on Windows simply right-click into the properties of the launcher. Then add --ignore-certificate-errors in the target field. Then restart Chrome.

How do I allow expired certificates in Chrome?

Navigate to the site with the cert you want to trust, and click through the usual warnings for untrusted certificates. In the address bar, right click on the red warning triangle and "Not secure" message and, from the resulting menu, select "Certificate" to show the certificate.

Does headless Chrome use cookies?

We're working on a project that requires to automatically login to a Google Account and few other services. However, as you may know, Headless Chrome does not remember cookies from previous instances, so we have to re-login to that account every time when we started a new Chrome instance.


1 Answers

There is an excellent article on medium.com by sahajamit

and i have tested the below code, it works perfectly fine with self-signed certificate https://badssl.com/

    ChromeOptions options = new ChromeOptions();     options.setExperimentalOption("useAutomationExtension", false);     options.addArguments("--headless", "--window-size=1920,1200","--ignore-certificate-errors");      DesiredCapabilities crcapabilities = DesiredCapabilities.chrome();     crcapabilities.setCapability(ChromeOptions.CAPABILITY, options);     crcapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);     crcapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);      System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "C:\\temp\\chrome\\chromedriver.log");     System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "C:\\temp\\chrome\\chromedriver.exe");      ChromeDriverService service = null;     try {         service = new ChromeDriverService.Builder()                 .usingAnyFreePort()                 .withVerbose(true)                 .build();         service.start();     } catch (IOException e) {         e.printStackTrace();     }      RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(),crcapabilities);      driver.get("https://self-signed.badssl.com/");     System.out.println(driver.getPageSource());     driver.quit(); 

software/framework versions

  • Google Chrome Version 64.0.3282.186
  • Google Chrome Driver Version 64.0.3282.186
  • Selenium version 3.11.0
like image 61
Amila kumara Avatar answered Sep 23 '22 04:09

Amila kumara