I’m having trouble getting ChromeDriver to work in headless mode when it needs to go through our company’s proxy server that requires authentication. The browser just won’t connect properly even though I’ve set up the proxy configuration.
Here’s what I’m trying to do:
public class ProxyTestAutomation {
private WebDriver browser;
@Test
public void setupHeadlessBrowserWithProxy() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\tools\\selenium\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
Proxy proxyConfig = new Proxy();
proxyConfig.setHttpProxy("http://username:[email protected]:8080");
proxyConfig.setSslProxy("http://username:[email protected]:8080");
// options.setCapability("proxy", proxyConfig);
options.addArguments("--proxy-server=username:[email protected]:8080");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--window-size=1920,1080");
browser = new ChromeDriver(options);
browser.get("https://www.google.com");
Thread.sleep(3000);
System.out.println("Page title: " + browser.getTitle());
assertTrue(browser.findElement(By.name("q")).isDisplayed());
browser.quit();
}
}
Can anyone help me figure out what’s wrong with my setup?
Corporate proxy authentication in headless Chrome is notoriously problematic because Chrome’s built-in authentication dialog can’t be displayed. You’ll need to use a proxy extension approach instead of command-line arguments. Create a Chrome extension that handles the authentication automatically by intercepting the onAuthRequired event and providing credentials programmatically. The extension should include a manifest.json with proxy permissions and a background script that listens for authentication challenges. Then load this extension using the --load-extension argument in your ChromeOptions. This bypasses the authentication popup issue entirely and works reliably in headless mode. I’ve used this method successfully in similar corporate environments where NTLM or basic auth is required.
dude, u should try using --proxy-auth=username:password instead of having creds in the proxy-server arg. also, consider adding --disable-web-security flag. corporate proxys are kinda finicky with ssl in headless mode.
I ran into this exact same issue at my previous job. The problem is that Chrome headless mode doesn’t handle proxy authentication prompts properly since there’s no UI to display them. What worked for me was switching to use a local proxy like CNTLM or Px that handles the corporate authentication on your behalf. Install CNTLM on your machine, configure it with your corporate proxy credentials, then point your ChromeDriver to use localhost:3128 instead of the corporate proxy directly. This way CNTLM handles all the authentication complexity while your headless Chrome just sees a simple local proxy without authentication requirements. Much more reliable than trying to hack Chrome extensions or authentication headers.