Chrome Headless Proxy Issue
I’m working on network traffic monitoring for my automated tests using BrowserMob proxy. Everything works great with regular Chrome browser but I’m getting empty pages when switching to headless mode.
Working Setup (Regular Chrome)
Proxy webDriverProxy = ClientUtil.createSeleniumProxy(mobProxy);
webDriverProxy.setNoProxy("<-loopback>");
webDriverProxy.setHttpProxy("localhost" + ":" + mobProxy.getPort());
webDriverProxy.setSslProxy("localhost" + ":" + mobProxy.getPort());
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, Boolean.TRUE);
caps.setAcceptInsecureCerts(Boolean.TRUE);
ChromeOptions chromeOpts = buildChromeOptions(config.getUserAgent(), Boolean.TRUE);
chromeOpts.setCapability(CapabilityType.PROXY, webDriverProxy);
caps.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
return new RemoteWebDriver(serverUrl, caps);
Broken Setup (Headless Chrome)
ChromeOptions headlessOpts = new ChromeOptions();
headlessOpts.addArguments("--user-agent=" + "HeadlessChrome");
headlessOpts.setAcceptInsecureCerts(Boolean.TRUE);
headlessOpts.setHeadless(true);
headlessOpts.addArguments("--allow-insecure-localhost", "--no-sandbox", "--disable-extensions", "--window-size=1920,1080");
List<String> proxyArgs = ImmutableList.of("--ignore-certificate-errors", "--proxy-bypass-list=<-loopback>",
"--proxy-server=http://localhost:" + proxyInstance.getPort(), "--remote-debugging-port=9222");
headlessOpts.addArguments("--ssl-protocol=any");
headlessOpts.addArguments("--allow-running-insecure-content");
headlessOpts.addArguments(proxyArgs);
capabilities.setCapability(ChromeOptions.CAPABILITY, headlessOpts);
webDriver = new RemoteWebDriver(remoteUrl, capabilities);
Current Configuration
- Driver endpoint: http://localhost:29515
- Proxy port: 33173 (dynamic)
- Proxy URL: http://localhost:33173
The Problem
Pages load as completely blank with this HTML:
<html><head></head><body></body></html>
I’ve tried adding waits and delays but nothing helps. When I use --proxy-bypass-list=* the pages load fine but then I can’t capture network traffic.
Environment Details
- browsermob-proxy version: 2.1.5
- ChromeDriver: 92.0.4515.159
- Running on remote Linux server
Proxy Initialization
System.setProperty("bmp.allowNativeDnsFallback", "true");
BrowserMobProxy proxyInstance = new BrowserMobProxyServer();
proxyInstance.setTrustAllServers(Boolean.TRUE);
I’ve been stuck on this for days and really need to get it working soon. Has anyone faced similar issues with headless Chrome and proxy setup?