yoni349
yoni349

Reputation: 117

Why console.log in puppeteer page.evaluate doesn't work?

Got this function from another developer and i'm trying to debug it. It's a web scraper based on puppeteer. But from some reason i can't console.log inside.

Can someone please point me to what am i'm missing here?

const getArticles = async (page) => {
  return await page.evaluate(() => {

  console.log('in page.evaluate')
//not printing anything in the console

    const products = document.querySelectorAll(".thumb-link")
    const formated = Array.from(products).map(x => x.href)
    console.log(22, formated)
    return Promise.resolve(formated.filter(x => x))
  });
}

let newArticles = await getArticles(page)

Upvotes: 3

Views: 3446

Answers (1)

mbit
mbit

Reputation: 3013

Add the following to see the browser's console log:

const page = await browser.newPage();
page.on('console', msg => console.log(msg.text()));

Upvotes: 4

Related Questions