Back to Resources


Posted September 23, 2013

Sauce Labs and Yes, the BrowserMob Proxy


As a consultant, I hear all too often, 'Our scripts are slow, how do we speed them up?' Part of the solution is to use the BrowserMob proxy to Get Rid of the 3rd Party Crap. Another situation where the BrowserMob proxy comes in handy is if you are accessing a site that uses Basic Authentication with WebDriver. But until now, making use of these tricks with Sauce wasn't an easy task. (Well, until last week actually.) The secret to making this work is the new --proxy option built in Sauce Connect version '3.0-r28, build 43'. It's not as simple as just adding a new flag when starting the tunnel so I'll walk through the steps then illustrate them in a concise script.

  1. Establish a BrowserMob proxy connection - The way the BrowserMob proxy works is you ask its main listening port for a new port that will actually be the proxy that the browser will be configured to access. You also want to request a client for each level of parallelization your are running; 3 concurrent browsers, 3 proxy clients.

  2. Establish the Sauce Connect tunnels - There are a couple flags that need to be used in order to make this work;

    • --proxy <PROXYHOST:PROXYPORT> - The PROXYHOST is the machine that the BrowserMob proxy is running on. PROXYPORT, the port of the BrowserMob client (or proxy) created.

    • --tunnel-identifier - Each of your BrowserMob proxy clients needs to have its own tunnel and in tests we need a way to say which tunnel we are talking about. The implication here is also that if you are doing 3 concurrent browsers, you have 3 tunnels.

    • --readyfile - The tunnel is being established programatically and takes a little bit of time. Computers being what they are, we need to have a way to tell in code that the tunnel is ready; watching for this file to appear on the disk is that bit of synchronization. (Shocking, a synchronization point when doing automation...)

Quick Tip: Do some research into your automation harness and figure out how do these first steps only once

  1. Light up a browser - Finally, we can start a browser. In order to get it to use the right proxy client you need to tell it the right tunnel. This is done via the tunnel-identifier capability and is where the tunnel identifier comes back into play.

  2. Manipulate the BrowserMob proxy - Blacklist, whitelist, basic authentication, etc.

  3. Do Stuff - Technical term for everything your script would normally do

  4. Close the browser.

Over, and over, and over as many times as you have scripts for. Once everything is done you need to shut it down.

  1. Close the tunnel - Killing the Sauce Connect process.

  2. Close the proxy - As of this writing, the BrowserMob proxy doesn't recycle ports, but it's a good practice to close things that you open.

Easy Peasy.

Sep 23, 2013
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.