LucianoGanga / simple-headless-chrome

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

getFrames returns a promise #52

Closed adamgotterer closed 7 years ago

adamgotterer commented 7 years ago

I'm trying to interact with getFrames but it doesn't return an object as the docs say, it actually returns a promise. I tried interfacing with the promise with no luck. How are you supposed to interact with it?

const HeadlessChrome = require('simple-headless-chrome')

const browser = new HeadlessChrome({headless: true})

async function navigateWebsite() {
  await browser.init();
  const mainTab = await browser.newTab({ privateTab: false });
  await mainTab.goTo('http://www.rollingstone.com')
  await mainTab.wait(10000);
  const frames = mainTab.getFrames();
  console.log(frames);
  await browser.close();
 }
 navigateWebsite();
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
strabbit commented 7 years ago

Just add an await to that line, so that it reads:

const frames = await mainTab.getFrames()

adamgotterer commented 7 years ago

Thank you! Still getting used to the await syntax :)