Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  151] [ 7]  / answers: 1 / hits: 32158  / 7 Years ago, wed, september 13, 2017, 12:00:00

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.


More From » node.js

 Answers
4

Update for puppeteer 12, adapted from the current documentation:


page.on('console', async (msg) => {
const msgArgs = msg.args();
for (let i = 0; i < msgArgs.length; ++i) {
console.log(await msgArgs[i].jsonValue());
}
});

await page.evaluate(() => console.log('hello', 5));
await page.evaluate(() => console.log({ foo: 'bar' }));
await page.evaluate(() => console.log([1, 2, 3, 4, 5]));

Shows the following results:


hello  
5
{ foo: 'bar' }
[ 1, 2, 3, 4, 5 ]

[#56495] Monday, September 11, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;