Puppeteer log inside page.evaluate

Alex Arvanitidis picture Alex Arvanitidis · Sep 13, 2017 · Viewed 14.8k times · Source

How can I console.log something inside the page.evaluate, passing it to node and using it during the evaluation of the page?

I actually want to log the progress of the page.evaluate to the console and show some results to the user.

Answer

Vaviloff picture Vaviloff · Sep 15, 2017

**Updated to work with puppeteer v1.4.x

If all you want is to "log the progress of the page.evaluate to the console", then just

const page = await browser.newPage();

page.on('console', consoleObj => console.log(consoleObj.text()));

And use console.log in page.evaluate as usual, no more dependencies are required.

Also see this nice tweak to remove multiple annoying warnings from log.