Recommended Free Tools
Listen for the page’s console event, then call msg.args() to get the values passed to the browser console call. Each value is a Puppeteer JavaScript handle: use jsonValue() for serializable data, or evaluate() to inspect a property in the page context. Use msg.text() when you only need a readable line.
Capture console messages in Node.js
Code running in the browser page does not automatically print its console output in Node.js. Attach a listener to the Puppeteer Page and forward the data you need. The Puppeteer debugging guide shows forwarding the readable message text; the ConsoleMessage API also provides the individual argument handles.
As an Amazon Associate I earn from qualifying purchases.
page.on('console', async msg => {
const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
console.log(`[${msg.type()}]`, msg.text(), args);
});
await page.evaluate(() => {
console.log('user:', { id: 42, active: true });
});
This example illustrates the API; it is not a claim of independent testing. For ordinary serializable values, the listener logs both the display text and the values converted from the argument handles. Choose one or both outputs to suit your logger.
Choose how to read the message
| What you need | Use | Important distinction |
|---|---|---|
| A readable console line | msg.text() |
This is display text, not the original argument array. |
| Individual arguments | msg.args() |
Returns an array of handles, one for each console argument. |
| Primitive or JSON-serializable values | handle.jsonValue() |
Returns serializable data; special objects may not become complete ordinary Node.js objects. |
| A particular property of an object | handle.evaluate(value => value.property) |
Reads the value in the page context without requiring a full object clone. |
| Message diagnostics | msg.type(), msg.location(), msg.stackTrace() |
Use these alongside text or arguments to identify the message and its source. |
The official API reference, displaying Puppeteer documentation version 25.12.0 when accessed on October 3, 2026, documents these ConsoleMessage methods. Its constructor is internal; consume the event object rather than creating a ConsoleMessage yourself: ConsoleMessage API.
#1 Best Overall
Inspect an object without cloning it
jsonValue() is convenient, but it is not a promise that every browser value will round-trip as a complete plain JavaScript object. Puppeteer’s execution guide notes, for example, that a DOM node returned from evaluate() may become {}. If you need only a field, evaluate against the handle in the page instead.
page.on('console', async msg => {
const handles = msg.args();
try {
const [labelHandle, objectHandle] = handles;
const label = await labelHandle.jsonValue();
const id = await objectHandle.evaluate(value => value.id);
console.log(label, id);
} finally {
await Promise.all(handles.map(handle => handle.dispose()));
}
});
This example expects a message with a label followed by an object that has an id property. Adapt the extraction to the shape of the console call you handle. For browser-side evaluation, Puppeteer serializes the callback and runs it in the page; it cannot implicitly access Node.js variables from the surrounding scope. Pass needed values as explicit arguments or define the needed logic inside the callback. See the JavaScript execution guide and JSHandle API.
Manage handle lifetimes in persistent listeners
A JSHandle keeps its referenced page object from being garbage-collected until it is disposed. In a listener that processes messages continuously, dispose of handles after extracting what you need, as in the example above. A handle is also automatically disposed when its associated frame navigates or its parent execution context is destroyed; do not use it after disposal or context destruction. These lifetime rules are documented in the JSHandle reference.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Troubleshoot common problems
- Nothing appears in Node.js: Browser console calls run in the page context. Register
page.on('console', ...)before the code that may log, then forward the message from the listener. - You see text but need separate values:
text()is a readable rendering. Useargs()and convert or inspect its handles. - An object is incomplete or empty: Special values, including DOM nodes, may not serialize into a useful plain object. Use a handle’s
evaluate()method to extract the specific property you need. - A handle operation fails after navigation: Navigation or destruction of the execution context automatically disposes associated handles. Capture and inspect the message in the relevant context, and do not reuse handles after they are disposed.
- The callback cannot see a Node.js variable: The function runs in the page context, not as a closure over Node.js. Pass data explicitly to the page evaluation or put the needed logic in the callback.
Or skip the browser setup
If your goal is to get a clean screenshot rather than inspect console arguments, ScreenshotNeo provides a one-request screenshot API. Its capture can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status.
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.
Rank #3
Frequently Asked Questions
Can I construct a Puppeteer ConsoleMessage myself?
No. The API reference describes its constructor as internal; handle the instance dispatched through the page’s console event.
Does msg.args() return plain JavaScript values?
No. It returns JavaScript handles. Convert serializable values with jsonValue(), or inspect a value in the page context with evaluate().
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




