Git Product home page Git Product logo

bmp-client's Introduction

BrowserMob Proxy Client

A library built to interact with browsermob-proxy's REST Api. Browsermob proxy has not been updated in several years, it is unlikely that this library will see any substantial updates anytime soon

Setup

  1. Ensure that you've downloaded browsermob-proxy and have it running
  2. npm install browsermob-proxy-client

Quick Start With Selenium

const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;
const selProxy = require('selenium-webdriver/proxy');
const bmpClient = require('browsermob-proxy-client').createClient();
//need to require this or it looks for a globally installed chromedriver
const chromedriver = require('chromedriver');

async function runBmp() {
  await bmpClient.start();
  await bmpClient.createHar();
  const driver = new webdriver.Builder()
    .forBrowser('chrome')
    .setProxy(selProxy.manual({ http: 'localhost:' + bmpClient.proxy.port }))
    .build();


  await driver.get("https://search.yahoo.com");
  const harData = await bmpClient.getHar();
  //do something
  console.log(harData);
  await bmpClient.end();
}

runBmp()
  .then(function () {
    console.log("Finished Successfully");
    process.exit([0]);
  })
  .catch(function (err) {
    console.error(err.message);
    console.error(err.stack)
    process.exit([1]);
  });

API

BrowserMobClient.createClient(config)

Synchronous function that instantiates a new client

  • config

    {
      browserMob:{ // *optional* details on where browsermob is running
         host:'localhost',
         port: 8080,
         protocol:'http'
       },
       proxy:{ // *optional*
         port:8081,
         bindAddress: `192.168.1.222`
       }
    }
    
client.callRest(url, method, data)

Method to make direct calls to browsermob-proxy's REST API see browsermob-proxy for available urls. Returns a promise.

client.closeProxies()

Returns a promise that closes all proxies running

client.createHar(options)

Returns a promise. Creates a har file on browsermob

  • options

    {
      captureHeaders: - Boolean, capture headers or not.
                           Optional, default to "false".
    
      captureContent: - Boolean, capture content bodies or not.
                    Optional, default to "false".
    
      captureBinaryContent:  Boolean, capture binary content or not.
                       Optional, default to "false".
    
      initialPageRef: - The string name of The first page ref
                   that should be used in the HAR. Optional,
                   default to "Page 1".
    
      initialPageTitle: - The title of first HAR page. Optional,
                      default to initialPageRef.
    }
    
client.end()

Returns a promise that stops the proxy port

client.getHar()

Returns a promise that resolves to a har in JSON format

client.listProxies()

Resolves to { proxyList: [ { port: 8081 }, { port: 8082 }, { port: 8083 } ]

client.setLimits(options)

sets limits on the proxy

  • options

    {
      downstreamKbps: - Sets the downstream bandwidth limit in kbps. Optional.
    
      upstreamKbps: - Sets the upstream bandwidth limit kbps. Optional, by default unlimited.
    
      downstreamMaxKB: - Specifies how many kilobytes in total the client is allowed to download through the proxy. Optional, by default unlimited.
    
      upstreamMaxKB: - Specifies how many kilobytes in total the client is allowed to upload through the proxy. Optional, by default unlimited.
    
      latency: - Add the given latency to each HTTP request. Optional, by default all requests are invoked without latency.
    
      enable: - A boolean that enable bandwidth limiter. Optional, by default to "false", but setting any of the properties above will implicitly enable throttling
    
      payloadPercentage: - Specifying what percentage of data sent is payload, e.g. use this to take into account overhead due to tcp/ip. Optional.
    
      maxBitsPerSecond: - The max bits per seconds you want this instance of StreamManager to respect. Optional.
    }
    
client.start(options)

starts a port to use

  • options

    {
      port: 'specify a port to start the proxy on',
      bindAddress: '192.168.1.222'    // if working in a multi-home env
    }
    

Development

Testing

  1. Install dependencies npm install

  2. Install and run browsermob-proxy

    npm run install-browsermob
    npm run start-browsermob
    
  3. Run the tests

    npm test
    

bmp-client's People

Contributors

benruns avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

bmp-client's Issues

bpm-client usage with protractor

Hi,

Just wondering if you can document an example of this with protractor-cucumber. I would like to use this client to proxy an application url and add headers to it so that I can SSO into the app. However, I do not have an idea as to how I should structure this. The example that you have is webdriverjs and though protractor does use webdriverjs under the hood we don't really instantiate the driver the way you have illustrated. I did take a stab at it using the browsermobproxy and here is my code for this: https://stackoverflow.com/questions/55094075/add-headers-to-home-page-url-using-browsermob-in-protractor-test-automation however the code doesn't work. So, hoping you can add an example or guide me at least with a blueprint as to how to go about using bmp-client with protractor

How to use createHar(options)

I tried to get the content of my response but i think im using createHar(options) wrong.

 var defaultProxy;
    defaultProxy = BrowserMob.createClient();
    await defaultProxy.start( );


    var caps = {
        'acceptSslCerts': 'true',
        'browserName': 'chrome',
        'record_network': 'true',
        'browserstack.console': 'verbose',
        'chromeOptions': {
            'args': ['--test-type', '--start-maximized', '--remote-debugging-port=9222', '-enable-benchmarking', '--enable-net-benchmarking', '--verbose', '--log-path=chromedriver.log']
        }

    };

let driver = new webdriver.Builder()
        .withCapabilities(caps)
        .setProxy(selProxy.manual(TestHelper.getManualProxy(defaultProxy.proxy.port)))
        .build();

await defaultProxy.createHar({
    captureContent:'true',
    captureBinaryContent: 'true'
});

*my requests...* 

const har = await defaultProxy.getHar();

i always get empty responses

"response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "HTTP/1.1",
      "cookies": [],
      "headers": [],
      "content": {
        "size": 0,
        "mimeType": "application/json;charset=UTF-8",
        "comment": ""
      },

Do you have an idea what i am doing wrong?

socks

I'm trying to use this to test a login form that uses a wss connection to execute the login. While all rest requests are successful and recorded with brosermob (navigating to the login page from the landing page, filling up the login form) when i click login button, proxy reports this error
(LittleProxy-20-ClientToProxyWorker-1) (AWAITING_INITIAL) [id: 0xe7fb21cb, L:/0:0:0:0:0:0:0:1:8100 - R:/0:0:0:0:0:0:0:1:56108]: An IOException occurred on ClientToProxyConnection: Connection reset by peer
and the connection is lost. If i disable the proxy while setting up selenium we driver, the loging is successful. Any ideas on why this is so and how to fix it?

Thanks

Readme

Example is wrong in the readme

Consider switching to the BrowserUp Proxy?

Hi BenRuns,

bmp-client looks like a really nice syntax around the BrowserMob proxy rest client.

I found your project while doing a github search for new development against the browsermob proxy. Development on the main browsermob proxy seems to have died in 2016. It is missing support for brotli, HTTP/2 and modern java versions.

We have a fork we are building that has those things. Anyhow, thought I'd mention it as it is a drop-in replacement with the same published REST API. I also maintain the most popular Ruby browsermob client and we will be switching that over to this fork. Cheers,

Eric

https://github.com/browserup/browserup-proxy

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
npm
package.json
  • request ^2.81.0
  • lodash ^4.17.4
  • request-promise-native ^1.0.3
  • chai 4.3.6
  • chromedriver 110.0.0
  • ip 1.1.8
  • mocha 10.2.0
  • selenium-webdriver 4.5.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.