Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Access Arguments from a Puppeteer Console Message

Puppeteer’s console event provides a ConsoleMessage. Use args() for its individual argument handles and jsonValue() to resolve ordinary serializable values in Node.js.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Listen for the page’s console event and call args() on the resulting ConsoleMessage. The method returns an array of Puppeteer handles—not ordinary Node.js values—so use jsonValue() to copy serializable arguments into Node.js.

Read the individual console arguments

Register a listener on the Puppeteer Page. Each event supplies a ConsoleMessage; its args() method returns the arguments as handles to values in the browser page’s JavaScript context.

As an Amazon Associate I earn from qualifying purchases.

page.on('console', msg => {
  console.log(msg.args());
});

The event can be emitted for different console methods, including console.log and console.dir, and also for page warnings and errors. Check Puppeteer’s ConsoleMessage API and the PageEvent documentation for the event and its payload.

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

Convert serializable arguments to Node.js values

For values that can be serialized, call jsonValue() on each handle. Since it returns a promise, await all the conversions before using the resulting array.

page.on('console', async msg => {
  const values = await Promise.all(
    msg.args().map(arg => arg.jsonValue())
  );
  console.log(values);
});

await page.evaluate(() => console.log(5, 'hello', { foo: 'bar' }));

Here the page logs three separate arguments. The listener resolves their handles and logs the resulting values in Node.js. Puppeteer’s API index describes JSHandle as a reference to a JavaScript object in the page context. A handle is not itself a plain Node.js object.

Choose between arguments and formatted text

Use msg.text() when the formatted message is sufficient. Use msg.args() when you need to preserve the arguments as separate values—for example, to distinguish a number from a string or inspect an object rather than only its displayed message.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
page.on('console', async msg => {
  const args = await Promise.all(
    msg.args().map(arg => arg.jsonValue())
  );

  console.log({
    type: msg.type(),
    text: msg.text(),
    args,
  });
});

For additional diagnostics, ConsoleMessage also exposes type(), location(), and stackTrace(). See the ConsoleMessage API reference for these methods.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Handle objects that do not serialize as expected

jsonValue() is suitable for ordinary serializable values, but do not assume every browser-side object can be copied intact into Node.js. If you need selected properties from a complex value, keep its handle and evaluate against it in the page context, or select the needed data in the page before returning it. Puppeteer’s Page documentation covers page evaluation.

For example, when logging a browser object, choose the fields you need instead of expecting the full object—including browser-specific or non-serializable state—to round-trip as a plain Node.js object.

Avoid missing early console messages

Attach the listener before the action that can emit the message. If application code logs during navigation or initialization, registering afterward can miss that event.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
page.on('console', async msg => {
  const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
  console.log(msg.type(), args);
});

await page.goto('https://example.com');

The exact timing depends on when the page runs its code; registering first ensures the handler is in place before navigation begins.

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

Filter by message type when needed

The console event is not limited to calls to console.log. It may also represent warnings and errors. Inspect msg.type() and filter in the handler if you only want a particular category.

page.on('console', async msg => {
  if (msg.type() !== 'log') return;

  const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
  console.log(args);
});
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • You see a message string but not separate values: msg.text() provides the message text. Use msg.args() to access the individual arguments.
  • The output contains handles rather than usable values: resolve serializable arguments with jsonValue(), typically using Promise.all for the array.
  • An argument does not become the expected plain object: it may not be suitable for serialization as-is. Keep the handle and inspect selected fields in the page context.
  • Startup messages are missing: install the console listener before navigation or other code that triggers them.
  • Warnings or errors are reaching a log-only handler: check msg.type() and filter for the message categories you intend to handle.

Or skip the browser setup

If you need a screenshot rather than console arguments, ScreenshotNeo can return an image or PDF from one request. It does not retrieve Puppeteer console arguments; use the Puppeteer listener above for that. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Example request (see the ScreenshotNeo API documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for the free plan: 1,000 screenshots a month, no card required.

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 *

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.