1
votes

I'm using browsermob proxy in order to capture traffic with webdrirver(chrome mostly). Here is the problem that I have: As long as I use single page everything is ok ,however when URL changes(due to navigating to other page or redirect), proxy is no longer captures any events (I'm not able to see those events in HAR file)

Here is how I start proxy:

BrowserMobProxyServer proxy = new BrowserMobProxyServer();
        try {
            proxy.start(Integer.valueOf(proxyPool.borrowProxyPort()), InetAddress.getLocalHost());
        } catch (NumberFormatException | UnknownHostException e) {
            Logger.error(e.getLocalizedMessage());
        }
        proxy.waitForQuiescence(30, 3, TimeUnit.SECONDS);
        proxy.setHarCaptureTypes(CaptureType.REQUEST_HEADERS);
        Logger.info("Proxy start status: " + proxy.isStarted());

And here is how I get har:

proxy.waitForQuiescence(10, 10, TimeUnit.SECONDS);
return proxy.getHar();

Do I need to somehow handle cases when URL changes or I'm missing smthn here?

1
Did you every find a solution for this? I have a similar issue where I need to capture the requests made by a new window that opens from clicking on a link.darkrat
Unfortunately, noMikhail

1 Answers

0
votes

This is how it worked for me!

BrowserMobProxyServer proxyBrowserMob = new BrowserMobProxyServer();
proxy.start();
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyBrowserMob)
    DesiredCapabilities caps = DesiredCapabilities.firefox();
 caps.setCapability("marionette", true);
    caps.setCapability(CapabilityType.PROXY, seleniumProxy);
RemoteWebDriver webDriver = new FirefoxDriver(caps);
proxyBrowserMob .enableHarCaptureTypes(CaptureType.REQUEST_CONTENT,CaptureType.REQUEST_HEADERS,CaptureType.REQUEST_COOKIES);
        proxyBrowserMob .newHar();

For retrieving HAR File, I iterate through a HarEntry to fetch the HAR.

List<HarEntry> entries = browserMobProxy.getHar().getLog().getEntries();
    for (HarEntry entry : entries) {
   // get HarRequest
   /get HarResponse
     }