When I try to print `msg.text` in 'console' event with type 'error', I got `JSHandle@error`
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 1.9.0
- Platform / OS version: macos
- URLs (if applicable):
- Node.js version: 8.11.3
What steps will reproduce the problem?
Please include code that reproduces the issue.
- Simply add these code in your page
try {
// try to print a value doesn't exist
// and it will throw an error
console.log(a)
} catch (e) {
// catch the error and print this with `console.error`
console.error(e)
}
- puppeteer script:
...
page.on('console', msg => {
console.log(msg.text())
})
...
What is the expected result?
It prints JSHandle@error
What happens instead?
The exact error object like ReferenceError: a is not defined...
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to get all console messages with puppeteer? including ...
I am fetching a page with puppeteer that has some errors in the browser console but the puppeteer's console event is not ...
Read more >A mostly complete guide to error handling in JavaScript.
Learn how to deal with errors and exceptions in synchronous and asynchronous JavaScript code.
Read more >You receive an error message when you try to print a ...
If you click Yes, your document is printed, but some text may be truncated and may not appear on the printed page. If...
Read more >Control flow and error handling - JavaScript - MDN Web Docs
(In C or Java, the equivalent code would have output 1 .) ... Depending on the type of error, you may be able...
Read more >JavaScript Console.log() Example – How to Print to the ...
Logging messages to the console is a very basic way to diagnose and troubleshoot minor issues in your code. But, did you know...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SidKwok you can use
msg.args()
to retrieve the array of arguments passed to console.BUT, since errors are not serializeable it won’t return the desired value. you can however, use the following as a workaround:
Yeah I agree, we should probably do a better job on getting error texts and everything. The way it’s supposed to be done atm is like this: