---
title: Use Browsermob proxy to retrieve HAR files with Selenium.
description: Manipulate traffic with this Selenium proxy, override HTTP headers, inspect
  HAR load times.
source_url:
  html: https://testingbot.com/support/other/proxy
  md: https://testingbot.com/support/other/proxy.md
---

# BrowserMob Proxy

We offer support for the [BrowserMob proxy](http://bmp.lightbody.net/) version 2.12 (updated August 16, 2016), which allows you to manipulate HTTP traffic during your Selenium tests.

 By using this proxy, you can: 
- Set/Get HTTP Headers during your tests. 
- Capture performance data with HAR files. 
- Simulate network traffic and latency. 
- Rewrite HTTP requests and responses. 

We provide a private and secure proxy, which works together with our grid and only you can access.   
 To get started, please follow the example below.

## Starting the proxy

 To start the proxy, make a GET request to our API like this:   

```bash
curl -u API_KEY:API_SECRET https://api.testingbot.com/v1/tunnel
```

The first time you initiate this request, we boot up a pristine virtual machine for you, which only you can access.   
 The response of this call will have a PENDING state, which means a server is being started for you.

```json
{"state":"PENDING","id":7977,"private_ip":null,"version":"2.8"}
```

 The average boot time is 45 seconds. To check the status of your machine, please use this command (replace 7977 with the id you received in the previous call): 

```bash
curl -u API_KEY:API_SECRET https://api.testingbot.com/v1/tunnel/7977
```

 The state should soon be READY. In the response you will find your personal server IP.   

```json
{"state":"READY","id":7977,"private_ip":"192.168.167.222","ip":"109.68.162.170","version":"2.8"}
```

You can now use this personal IP (109.68.162.170 in this example) as your BrowserMob proxy. The port will always be 9090.

## Using the proxy

Please see the [README file on GitHub](https://github.com/lightbody/browsermob-proxy) for all of the BrowserMob proxy's commands.   
 An example where we will collect performance data in a HAR file, together with a Selenium test run by Ruby would be:

 Create a new proxy by making this request to your personal IP **(replace 109.68.162.170 with the IP you received)**: 

```bash
curl -X POST http://109.68.162.170:9090/proxy
```

 In the response you will receive a port which you can use as proxy.   
 For this example, we will assume the returned port is 9091. 

 Now create a HAR attached to the proxy we just created: 

```bash
curl -X PUT http://109.68.162.170:9090/proxy/9091/har
```

 Run your test:

```ruby
#!/usr/bin/env ruby
require "rubygems"
require 'testingbot'
gem "selenium-webdriver"
require "selenium-webdriver"

caps = {
  :browserName => "firefox",
  :browserVersion => "latest",
  :platformName => "WIN11",
  :proxy => Selenium::WebDriver::Proxy.new(:http => "109.68.162.170:9091") #use the 9091 port and personal ip we retrieved earlier
}

urlhub = "https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub"
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120

@webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client
@webdriver.navigate.to "https://testingbot.com/"
puts @webdriver.title
@webdriver.quit
```

 Once the test has finished, you can obtain the HAR file from your proxy: 

```bash
curl http://109.68.162.170:9090/proxy/9091/har
```

## Use BrowserMob with our Tunnel

The good thing about the Browsermob proxy is that you can specify an upstream proxy, meaning we can use the Browsermob proxy in our tests and set its upstream proxy to our [Tunnel](https://testingbot.com/support/tunnel).

So to start this process, here's what should happen:

- Start a tunnel, with the java -jar TestingBot-Tunnel.jar
- Wait until the tunnel is ready
- Fetch its private IP via cURL: 

```bash
curl -u API_KEY:API_SECRET https://api.testingbot.com/v1/tunnel
```

- This should return something like: 

```json
{"state":"READY","id":7977,"private_ip":"192.168.167.222","ip":"109.68.162.170","version":"2.8"}
```

- Use the private\_ip as upstream proxy with Browsermob: 

```bash
curl -X POST "http://[ip]:9090/proxy?httpProxy=[private_ip]:2009"
```

- This will return a port, for example 9092
- Start recording the traffic in HAR format: 

```bash
curl -X PUT -d 'initialPageRef=Foo' http://[ip]:9090/proxy/9092/har
```

- Run your test with proxy 109.68.162.162 and port 9092
- When test is done, collect HAR results: 

```bash
curl http://[ip]:9090/proxy/9092/har
```

## Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new) [Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
