2

I've created simple method for get network traffic from Chrome:

 public void saveNetworkTraffic() {
    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/bin/chromedriver");
    String sFileName = "networklog.xar";

    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start(0);

    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);

    WebDriver driver = new ChromeDriver(capabilities);
    WebDriverRunner.setWebDriver(driver);

    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

    proxy.newHar("google.com");

    driver.get("http://google.com/");
    Har har = proxy.getHar();

    File harFile = new File(sFileName);
    try {
        har.writeTo(harFile);
    } catch (IOException ex) {
        System.out.println(ex.toString());
        System.out.println("Could not find file " + sFileName);
    }
}

When browser opens a page it shows an error "ERR_EMPTY_RESPONSE" on this step driver.get("http://google.com/") instead of usual google page in Chrome. I've tried to figure out the reason for the error, but according to the https://github.com/lightbody/browsermob-proxy#using-with-selenium, my code should work fine.

Gokul
  • 690
  • 2
  • 13
  • 26
Konstantin
  • 75
  • 1
  • 8

2 Answers2

0

Your code look fine, try adjusting the dependencies like:

        <dependency>
            <groupId>net.lightbody.bmp</groupId>
            <artifactId>browsermob-core</artifactId>
            <version>2.1.5</version>
        </dependency>
Pankaj Kumar Katiyar
  • 1,416
  • 1
  • 20
  • 32
0

Add this code, try it:

proxy.addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(new ResponseFilter() {
            @Override
            public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {}}, Integer.MAX_VALUE));

enter image description here

Christopher Moore
  • 8,731
  • 9
  • 17
  • 33
  • Welcome to StackOverflow! Please, take a look about [how to format your code](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks#:~:text=Use%20the%20%7B%7D%20button%20above,%E2%8C%98%20K%20on%20OS%20X) and so, avoid to put images as code – xKobalt Aug 25 '20 at 06:45