Headless chrome + ignore-certificate-errors Headless chrome + ignore-certificate-errors google-chrome google-chrome

Headless chrome + ignore-certificate-errors


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


@amila-kumara is working but, usage of DesiredCapabilities.chrome() gives warning to use ChromeOptions. Please see the updated answer.

Set the chrome option values

System.setProperty("webdriver.chrome.driver", Config.NDAC_WEBDRIVER_PATH);ChromeOptions options = new ChromeOptions();options.addArguments("--window-size=1920,1200");options.setAcceptInsecureCerts(true);options.setHeadless(true);

Start the service

ChromeDriverService service = null;try {    service = new ChromeDriverService.Builder()            .usingAnyFreePort()            .withVerbose(true)            .build();    service.start();    remoteWebdriverUrl = service.getUrl();    System.out.println("Starting the url " + remoteWebdriverUrl);} catch (IOException e) {    e.printStackTrace();}

Note: I was facing the issue while closing the driver(with RemoteWebDriver), chromedriver.exe process won't close even when you use driver.quit(). To fix the issue use ChromeDriver instead of RemoteWebDriver

RemoteWebDriver driver = new ChromeDriver(service, options);

To properly close the driver, use

driver.close();driver.quit();


This works for me on ChromeDriver 80.

ChromeOptions option = new ChromeOptions();option.AddArgument("--headless");option.AcceptInsecureCertificates = true;driver = new ChromeDriver(option);