Search code examples
javaseleniumbrowsermob-proxy

BrowserMob Proxy Questions


Is anyone familiar with using BrowserMob Proxy? I need some help.

https://github.com/lightbody/browsermob-proxy/blob/master/README.md

My goal is to try to use BrowserMob Proxy to detect that certain events are fired in the Network Tab. Any idea how to do this?

The language is in Java and I am using the Selenium Grid framework.


Solution

  • With the following code you can get the HAR archive.

    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start(0);
    HashSet<CaptureType> enable = new HashSet<CaptureType>();
    enable.add(CaptureType.REQUEST_HEADERS);
    enable.add(CaptureType.REQUEST_CONTENT);
    enable.add(CaptureType.RESPONSE_HEADERS);
    proxy.enableHarCaptureTypes(enable);
    HashSet<CaptureType> disable = new HashSet<CaptureType>();
    disable.add(CaptureType.REQUEST_COOKIES);
    disable.add(CaptureType.RESPONSE_COOKIES);
    proxy.disableHarCaptureTypes(disable);
    
    //get the Selenium proxy object
    Proxy selProxy = ClientUtil.createSeleniumProxy(proxy);
    
    capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, selProxy);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
    
    FirefoxProfile profile = new FirefoxProfile();
    WebDriver driver = new FirefoxDriver(new FirefoxBinary(),profile,capabilities);
    
    
    driver.get(url);
    
    Har har = proxy.getHar();
    

    Then explore the har object entries as you need