Performance data collection using BrowserMob Proxy and Selenium

BrowserMob Proxy with Selenium

BrowserMob Proxy is a simple utility that makes it easy to capture performance data from browsers, typically written using automation toolkits such as Selenium and Watir.

BrowserMob Proxy can capture performance data for web apps (via the HAR format). Used to collect the performance data from the client side.

What is a HAR format ?

HAR(HTTP Archive) is a online tool visualizing. HAR is produced by the HTTP tracking tools, these files captures the details of the client/server communication and this can be used for analysis like Page Load Performance.

How the HAR files will look ?

proxy is programmatically controlled via a REST interface or by being embedded directly inside Java-based programs and unit tests.It can control HTTP trafic for,

  • blacklisting and whitelisting certain URL patterns
  • simulating various bandwidth and latency
  • remapping DNS lookups
  • flushing DNS caching
  • controlling DNS and request timeouts
  • automatic BASIC authorization

How to Use BrowserMob Proxy?
Step 1: Download the BrowserMob Proxy

Step 2: Start the proxy by running browsermob-proxy on Mac/*Nix based machines and browsermob-proxy.batfor Windows in the bin directory
On Mac it should be like sh browsermob-proxy -port 9090

Step 3: You can create a New Java Project in Eclipse as documented here

Step 4: You use the below mentioned Java code as an example,

You will have to add all the jar files that are in lib folder in the downloaded package to this Eclipse Project Build Path

Step 5: Run the script as Right click and Run As Java Application

Step 6: You can view the Eclipse console for run time logs generated

Step 7: Refresh your project, now you can see a folder HAR files is generated inside the HARFiles folder

You can now view the Har file for performance data here

Now we can view the performance data for and it looks like the below screenshot,

Hope this post helps in setting up the BrowserMob Proxy.

Please share and leave your comments if any.


The same implementation in .NET C#

[sourcecode collapse=”false” language=”csharp”]
using AutomatedTester.BrowserMob.HAR;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace BrowserMob.PerfTest
public class ExampleClass
public void ExampleUse()
// Supply the path to the Browsermob Proxy batch file
Server server = new Server(@"C:BrowserMobProxybinbrowsermob-proxy.bat");

Client client = server.CreateProxy();

var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var profile = new FirefoxProfile();

// Navigate to the page to retrieve performance stats for
IWebDriver driver = new FirefoxDriver(profile);

// Get the performance stats
HarResult harData = client.GetHar();

// Do whatever you want with the metrics here. Easy to persist
// out to a data store for ongoing metrics over time.


The Python Implementation
[sourcecode collapse=”false” language=”python”]
from browsermobproxy import Server
server = Server("path/to/browsermob-proxy")
proxy = server.create_proxy()

from selenium import webdriver
profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile)

proxy.har # returns a HAR JSON blob


29 thoughts on “Performance data collection using BrowserMob Proxy and Selenium”

      • I am using this with ASP .Net C#.
        But I am facing an issue that I am not able to remap host or you can say the browser mob proxy is not reading my host file .
        I found that calls to remap a host is available in java but not in Asp .net c#.
        Please help me if you have any idea on this.

        Ramesh Jhajharia

  1. Hey Ramesh,
    I saw your post in the Google Groups as well. I have just started looking at the .NET bindings of BrowserMob Proxy. I will post the code here for the same If I get to work them properly.

    Havent fully explored all the API’s in Java itself. Let me try to help you out soon.


  2. great article. I was able to implement the browsermob proxy using C# however what i’m finding it difficult to understand is how do i go about implementing it for my whole project? I mean i have a login page, and when the login button is being clicked i’m being redirected to the same page instead of having the app proceeding to the next screen. does this mean that browsermob proxy has to be implemented each time i want to monitor traffic?

  3. Hi monoj, when i am trying to run using above code. i am getting some proxy issues. Firefox is opening and giving a message stating: Firefox is configured to use a proxy server that is refusing connections.
    Check the proxy settings to make sure that they are correct.
    Contact your network administrator to make sure the proxy server is
    Do i need to change any settings to make it work? please let me know

    • That is completely dependent on the network that you use. I think you are under a firewall protected environment, where you are using your AD credentials to access the webpages ? If yes, you can configure Firefox with proxy or add the webpage under exemption list

  4. using python on windows:
    from browsermobproxy.server import Server
    from selenium import webdriver

    server = Server(“Libbrowsermobproxybin”)
    proxy = server.create_proxy()

    profile = webdriver.FirefoxProfile()
    driver = webdriver.Firefox(firefox_profile=profile)

    proxy.har # returns a HAR JSON blob


    i get

    from browsermobproxy.server import Server
    ImportError: No module named server

    even if the import is the one Eclipse suggested for Server

    i have:
    python 2.7
    selenium 2.27
    browsermob 0.20
    and I run the test from eclipse

    any suggestions?


  5. Hi All,

    My main goal is to create the har files.

    I tried using the above code and works fine but if I test a site which requires login cedentials i,e session id, it fails past the login screen. Below is the code snippet
    driver.get(_sBaseURL + “/Login/Login.aspx”);
    driver.findElement(“User.UserName”)).sendKeys(new String[]{“jmathe02”});
    driver.findElement(“User.Password”)).sendKeys(new String[]{“cat1dog”});

    However if I change to proxy to use ProxyType.Direct it works but then does not create the har entires.

    Was wondering if some could help.


  6. Hi, i’m trying to use the browser-mob proxy npm module for testing the network traffic using Javascript connected to sauce labs. I use the version 1.0.9 of browser-mob proxy. When I start the proxy server, I get an error. Suggest me is this possible?

    • I will add to this post or create a new one on using bmp js module. I am using with Protractor now, so expect a new post soon.

  7. HI,

    Can you please let me know which version of SElenium, browsermob and firefox are you using?
    I am using selenium-server-standalone-2.35, browsermob-proxy-2.0-beta-6.jar and Firefox 22.
    I am getting proxy server is refusing connection.
    Do I also need to run the browsermob batch file?


  8. Hi Manoj,
    Thanks for the share, however I always get
    “The proxy server is refusing connections on browser”, it never launches the webpage. Followed the same example. is there any setting which also needs to be take care?


  9. Hi Manoj,

    Can we get request headers through selenium without using fiddler?
    I am using Chrome selenium in C#.


  10. This is working fine on my machine. But after implementing this, automation suite execution automatically slow down.
    Can anyone explain how can I fixed this issue


Leave a Comment