DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Read Arguments from Puppeteer Console Messages

Capture Puppeteer console messages in Node.js, read their individual arguments, inspect object properties safely, and handle serialization and lifetime issues.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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. Use args() 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.