Skip to content

working example #1

@Galileo1

Description

@Galileo1

Would you be able to post a working example that could help users understand more about the library and how it works?? My code and output is as below. And I can't really interpret that output.

Code ->

`const bmpClient = require('browsermob-proxy-client-nodejs');
const request = require('request');
const fs = require('fs');

const bmpHost = '127.0.0.1'; //ip where BrowserMob Proxy was started
const bmpPort = 8080; //tcp port where BrowserMob Proxy was started

let browserMobProxyClient = undefined;

(new bmpClient(bmpHost, bmpPort)).create()
.then((client) => {
//Browser Mob Client
browserMobProxyClient = client;
})
.then(() => {
//start capture a traffic
return browserMobProxyClient.newHar(true, true, true);
})
.then(() => {
//make some request through browsermob proxy, that has started above
const proxy = http://${bmpHost}:${browserMobProxyClient.port}
return makeSomeRequestThroughProxy(proxy); //it is a imaginary function
})
.then(() => {
//get HAR
return browserMobProxyClient.getHar();
})
.then((har) => {
//make some action with HAR
console.log(har : ${JSON.stringify(har)});
fs.writeFileSync('com.har', har, 'utf8');
console.log(written har);
})
.catch((value) => {(new Error(value));});

function makeSomeRequestThroughProxy(proxy){
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
console.log(proxy : ${proxy});
let r = request.defaults({'proxy': proxy});
r.get('https://yahoo.com/')
.on('response', (response) => {
console.log(code : ${response.statusCode}) // 200
});
}`

Output ->
request : http://127.0.0.1:8080/proxy?trustAllServers=true; method : POST parsed body : { port: 8093 } request : http://127.0.0.1:8080/proxy/8093/har; method : PUT parsed status (OK) : 204 proxy : http://127.0.0.1:8093 request : http://127.0.0.1:8080/proxy/8093/har; method : GET parsed body : { log: { version: '1.2', creator: { name: 'BrowserMob Proxy', version: '2.1.4', comment: '' }, pages: [ [Object] ], entries: [], comment: '' } } har : {"log":{"version":"1.2","creator":{"name":"BrowserMob Proxy","version":"2.1.4","comment":""},"pages":[{"id":"Page 0","startedDateTime":"2017-12-29T15:53:55.096+05:30","title":"Page 0","pageTimings":{"comment":""},"comment":""}],"entries":[],"comment":""}} written har code : 200

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions