-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console.log() from page.evaluate() not working #1944
Comments
It is working but it's not outputting to node environment console. Have a look at page.on('console', msg => {
for (let i = 0; i < msg.args.length; ++i)
console.log(`${i}: ${msg.args[i]}`);
});
page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); |
everything that is run inside the page.evaluate function is done in the context of the browser page. The script is running in the browser not in node.js so if you log it will show in the browsers console which if you are running headless you will not see. You also can't set a node breakpoint inside the function. |
you can capture it with page.on('console' even in headless |
@Everettss thanks for the example, but It does not seem to work with |
Page.on('console', (msg) => {}) actually fired, but the example will not work because msg.args is undefined. Inside the callback, just console.log(msg) we will see what is inside. |
Just one more thing, the page.on('console', callback) should be registered before any console.log statement can be called |
谢谢 @c094728 解答,如果还有问题,戳右边链接。https://guozh.net/puppeteer-page-evaluate-consolelog-not-working/ |
For anyone looking at this issue now, in the latest version, you'll need to do this instead:
args has been replaced with _args |
as referred, @Ed-Ed @Everettss above code does work! |
For the full message logs this worked for me:
|
this does not trigger for |
Slight improvement to @ezy's solution. This will print the message type and the resolved message text from the console args. page.on('console', (msg) => console[msg._type]('PAGE LOG:', msg._text)); |
I don't know why this hasn't been mentioned here but simply setting |
@whoisjuan Thanks!!
|
in 2023 Sep, I have to use |
I'm also having this problem seems to have stopped working after |
Hello,
I'm trying to console.log() in a page.evaluate() function and it's not working...
Any solutions ?
Thank you !
The text was updated successfully, but these errors were encountered: