LucianoGanga / simple-headless-chrome

Simple abstraction to use Chrome as a Headless Browser with Node JS
MIT License
217 stars 50 forks source link

browserIsInitialized is not a function #58

Closed mmarsella closed 7 years ago

mmarsella commented 7 years ago

Hello again!

I am trying to call browserIsInitialized on a tab (as its listed in the readMe) or on the browser and both return an error:

mainTab.browserIsInitialized is not a function or browser.browserIsInitialized is not a function.

Here is the example I used:

    await browser.init()

    // Open up a new tab
    let mainTab = await browser.newTab();
        // This will return an error
    let browserAlive = await mainTab.browserIsInitialized()

    console.log('Browser Alive?', browserAlive);

I looked at your Browser class and it seems like isInitialized method returns !!this.client.

I tested that in this example - and that works fine:

    await browser.init()

    // Open up a new tab
    let mainTab = await browser.newTab();

    let browserAliveNow = await browser.isInitialized()
    console.log('Browser Alive?', browserAliveNow); //true

    console.log(!!mainTab.client);  // true
    console.log(!!browser.client);  // true

    await   browser.close();
    console.log('-- AFTER BROWSER CLOSED --')
    console.log(!!mainTab.client);  // true
    console.log(!!browser.client);  // false

    let browserAlive = await browser.isInitialized()
    console.log('Browser Alive?', browserAlive); //false

The way your documentation is structured - it appears the browserIsInitialized is a method on a new tab (like evaluate, goTo, etc...). Maybe this needs to be listed as a method on the browser instead?

I can make a PR if you would like.

Thanks Lucho, M

LucianoGanga commented 7 years ago

Hi @mmarsella !

It's possible that the docs are not quite right :/

I don't have time to review it all everytime I merge a PR or I make some changes (that's why I'm trying to do more tests and working examples, I think they're better for a quick start with this module).

Of course, if you can fix the docs so it's according to the code, I'll really appreciate that!

Let me know if I can help with that :)

Thanks! Lucho

LucianoGanga commented 7 years ago

Hello @mmarsella !

I was reviewing this, and the thing is that it's a method in both, the browser and the tab. That's because whenever there's a new tab, the CDP is attached to it and it also may have an initialized state.

So in the docs, what's missing is the docs about the browser object.

I'm gonna update that when I improve the documentation generation (right now it's automatically generated using documentationjs)

Thanks! Luciano