zzo / browsermob-node

Javascript bindings for browsermob-proxy
MIT License
81 stars 33 forks source link

TypeError: browser.init is not a function #33

Open hubitor opened 5 years ago

hubitor commented 5 years ago

I'm seeing this error:

DEBUG @wdio/config: @wdio/sync found, running tests synchronous
mytest/node_modules/browsermob-proxy/index.js:36
            .init()
             ^

TypeError: browser.init is not a function
    at Proxy.selFunc (mytest/node_modules/browsermob-proxy/index.js:36:14)
    at mytest/node_modules/browsermob-proxy/index.js:171:31
    at mytest/node_modules/browsermob-proxy/index.js:140:25
    at IncomingMessage.<anonymous> (mytest/node_modules/browsermob-proxy/index.js:232:21)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1103:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

for every example I've tried including the example from here:

var Proxy = require('browsermob-proxy').Proxy,
    proxy = new Proxy(),
    fs = require('fs');

proxy.doHAR('http://yahoo.com', function (err, data) {
    if (err) {
        console.error('ERROR: ' + err);
    } else {
        fs.writeFileSync('yahoo.com.har', data, 'utf8');
    }
});

I start browsermob-proxy like this: $ /bin/sh /home/user/browsermob-proxy-2.1.4/bin/browsermob-proxy

and Selenium Server like this: ./node_modules/webdriver-manager/bin/webdriver-manager start --standalone

barocsi commented 4 years ago

It seems there is an issue with the webdriverio initialization at index.js line 36: <rejected> Error: Required option "capabilities" is missing Did you manage to resolve this issue?

hubitor commented 4 years ago

Nope. I was using this: https://github.com/cyrus-and/chrome-har-capturer lately.

lasertiger commented 4 years ago

I have the same problem.

kalpeshchilka commented 4 years ago

I am facing a similar issue. How to fix this? Is there any alternative repo and blog to help with this.

franzcatch commented 4 years ago

I am facing the same problem.

This seems to be the offending line: https://github.com/zzo/browsermob-node/blob/master/index.js#L35

I put a console.log(browser) just above it and what comes out is a Promise. So webdriverio.remote appears to be returning a promise. I am not super well versed in this, but I am trying to pair this with Protractor - which uses webdriver-manager. The version I am running is 12.1.7. Running webdriver-manager status reveals the following versions:

[11:06:52] I/status - selenium standalone version available: 3.141.59 [last]
[11:06:52] I/status - chromedriver version available: 83.0.4103.39 [last]
[11:06:52] I/status - geckodriver version available: v0.26.0 [last]
[11:06:52] I/status - android-sdk is not present
[11:06:52] I/status - appium is not present

It appears that the webdriverio inside selenium 3.141.59 must have had some fundamental functionality changes since the last time browsermob-node was updated. Thing is, I don't know which version I "should" be running that is compatible with the latest version of browsermob-node.

Just for grins, I modified my local version of browsermob-node like this:

    selFunc:  async function(proxy, url, cb) {
        var browser = await webdriverio.remote({
            host: this.selHost
            , port: this.selPort
            , capabilities: { browserName: 'firefox', seleniumProtocol: 'WebDriver', proxy: { httpProxy: proxy } }
            , desiredCapabilities: { browserName: 'firefox', seleniumProtocol: 'WebDriver', proxy: { httpProxy: proxy } }
        });

        browser
            .init()
            .url(url)
            .end(cb);
    },

Note that webdriverio.remote was also complaining about capabilities missing - so I copied desiredCapabilities to it.

This no longer blows up with the error shown in the OP above, but I am still not able to capture any traffic. Likely more compatibility issues?