Chrome headless browser returning blank HTML with BrowserMob Proxy - any solutions?

I’m having trouble with BrowserMob Proxy and Chrome headless browser in my UI automation tests. It works fine with regular Chrome, but the headless version gives me empty HTML responses. Here’s what I’ve tried:

  • Set up proxy settings for both regular and headless Chrome
  • Added various Chrome options and capabilities
  • Used dynamic ports for BrowserMob Proxy
  • Tried different proxy bypass settings
  • Added waits and delays

But I still get a blank page when taking screenshots on test failures. The HTML dump is just an empty structure.

I’m using:

  • BrowserMob Proxy 2.1.5
  • ChromeDriver 92.0.4515.159
  • Running on a remote Linux CLI system

Has anyone encountered this before? Any ideas on how to fix it? I’m on a tight deadline and could really use some help troubleshooting this issue.

// Sample code snippet (different from original)
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu");
options.setProxy(proxySettings);

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, options);

driver = new RemoteWebDriver(hubUrl, caps);

Thanks in advance for any suggestions!

I’ve faced similar issues with headless Chrome and BrowserMob Proxy. One thing that worked for me was explicitly setting the window size for the headless browser. Sometimes, the default viewport can be too small, causing rendering issues.

Try adding these arguments to your ChromeOptions:

options.addArguments("--window-size=1920,1080");
options.addArguments("--start-maximized");

Another potential solution is to disable the Chrome sandbox when running in headless mode:

options.addArguments("--no-sandbox");

If those don’t work, you might want to check if there are any JavaScript errors preventing the page from rendering properly. You can try enabling verbose logging for ChromeDriver to get more insight:

System.setProperty("webdriver.chrome.verboseLogging", "true");

Lastly, ensure your Linux system has all the necessary dependencies for running Chrome headless. Sometimes missing libraries can cause unexpected behavior. Hope this helps!

I encountered a similar issue when working on a project last year. One solution that resolved it for me was updating to the latest version of ChromeDriver and ensuring it matched my Chrome browser version exactly. Mismatched versions can cause unexpected behavior, especially with headless mode.

Additionally, have you tried setting a user agent string explicitly? Sometimes headless Chrome can be detected and blocked by certain websites. Add this to your options:

options.addArguments(“–user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36”);

Lastly, double-check your proxy configuration. Ensure the proxy is actually running and accessible from your test environment. You might want to try connecting to the proxy manually to verify it’s working as expected.

have u tried using a different proxy solution? i had similar probs with browsermob and switched to zap proxy. it worked better for me with headless chrome. also, check ur network settings on the linux box. sometimes firewalls can mess things up. good luck!