Chrome headless is not working with specific profile, it is picking random default profile

1.3k Views Asked by At

I have a problem with running my selenium test in headless mode with some specific profile (with extensions). without headless, the script is working file (with specific profile), but with the headless mode, it is picking default profile which resulted in the failure of the script.

Tried some ways to solve this issue, but nothing worked.

  1. chromeOptions.setAcceptInsecureCerts(true); chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); chromeOptions.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

  2. chromeOptions.addArguments("--remote-debugging-port=23456"); - this resulted in error at this port.

    code setup for starting chrome browser in headless mode.

    chromeOptions.setExperimentalOption("excludeSwitches", 
    Arrays.asList("disable-sync", "enable-logging"));
    chromeOptions.addArguments("--enable-sync");
    chromeOptions.addArguments("--disable-logging");
    chromeOptions.addArguments("--no-sandbox");
    chromeOptions.addArguments("--disable-dev-shm-usage");
    
    chromeOptions.addArguments("--headless");
    chromeOptions.addArguments("--disable-gpu");
    chromeOptions.addArguments("--window-size=1280,800");
    chromeOptions.addArguments("--allow-insecure-localhost");
    chromeOptions.addArguments("--remote-debugging-port=45447");
    
    chromeOptions.setAcceptInsecureCerts(true);
    chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    chromeOptions.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
    
1

There are 1 best solutions below

0
On BEST ANSWER

Adding extensions are not supported with headless run. So, used "Xvfb" virtual frame buffer to mock the chrome UI. Remove "--headless" while starting the browser instance.