October 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 ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Read Browser Console Messages in Puppeteer

Use Puppeteer’s page console event to forward browser messages into Node.js, classify them, and trace their source—with notes on what console events cannot diagnose.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Attach a console event listener to the Puppeteer Page before the page action that may produce a message. In the handler, use msg.text() to print its readable text, msg.type() to identify its console category, and msg.location() or msg.stackTrace() to trace its source. Browser-side messages do not automatically appear in Node.js; forward them explicitly.

Forward page console messages to Node.js

The listener runs in your Node.js process and receives a ConsoleMessage when page JavaScript calls a console method. Register it on the relevant page before navigating, evaluating code, or taking another action that might log.

As an Amazon Associate I earn from qualifying purchases.

page.on('console', msg => {
  console.log(`[${msg.type()}] ${msg.text()}`);
});

For example, after registering the listener, this page-side call produces a message that the handler can print in the Node.js terminal:

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.
await page.evaluate(() => console.log('hello from the page'));

The console.log inside page.evaluate() runs in the browser page. The handler’s console.log runs in Node.js. Puppeteer’s debugging guide explains that client-side console.* calls do not directly log to Node.js.

Use the right ConsoleMessage field

A ConsoleMessage offers several views of the same event. Choose the fields that answer your debugging question rather than logging everything by default.

Method What it gives you Useful when
text() A string containing the formatted message text. You want readable terminal or test output.
type() The console method category, such as log, info, warn, error, dir, table, trace or assert. You want to filter, label or count categories.
args() The arguments passed to the console call. You need access to the original arguments rather than only formatted text. Check how remote objects are represented in the Puppeteer version you use.
location() The message’s source location. You want a direct location for a log entry.
stackTrace() An array of locations on the message’s stack. You need more source context than one location provides.

These methods are documented in the ConsoleMessage class reference; categories are listed in the ConsoleMessageType reference.

Print warnings and errors only

Compare type() with the categories you care about. This example includes the message and its location:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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', msg => {
  if (msg.type() === 'error' || msg.type() === 'warn') {
    console.log(`[${msg.type()}] ${msg.text()}`, msg.location());
  }
});

This filters console events; it is not a guarantee that every browser warning, failed request or other failure will appear as a console event.

Complete runnable example

Install Puppeteer in a Node.js project with npm install puppeteer, then save this as an ES module file such as console-log.mjs and run node console-log.mjs. The listener is installed before the page-side messages are generated.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();

  page.on('console', msg => {
    console.log(`[${msg.type()}] ${msg.text()}`);
    console.log('source:', msg.location());
  });

  await page.evaluate(() => {
    console.log('example message');
    console.warn('example warning');
  });
} finally {
  await browser.close();
}

To inspect original arguments or additional stack locations, add msg.args() or msg.stackTrace() to the handler. The example uses documented Puppeteer methods from the ConsoleMessage reference.

What the console event does—and does not—cover

Puppeteer documents the page’s console event for JavaScript console API calls; its event documentation also describes emission when the page throws an error or warning. The payload is a ConsoleMessage. See the PageEvent reference.

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

Console output is one diagnostic view, not a complete record of everything happening in the browser. A missing message does not establish that the page loaded successfully or that no request, browser-process or Node-side problem occurred. Pick a diagnostic method that matches the failing layer:

  • Page JavaScript: forward console events as shown above; use a visible browser and slow actions when you need to observe what the page does.
  • Browser-side execution: enable DevTools and use a debugger statement in browser-side code when stepping through it is more useful than terminal logs.
  • Node.js Puppeteer code: use Node’s inspector to investigate server-side execution.
  • Puppeteer protocol traffic: the debugging guide documents protocol logging with NODE_DEBUG. Treat these logs carefully because they may contain sensitive information.
  • Browser process output: the guide documents forwarding browser process logs with dumpio.

These additional approaches are described in Puppeteer’s debugging guide.

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

Troubleshooting missing or unhelpful messages

  • No message appears in the Node terminal: confirm you attached page.on('console', ...) to the same Page that runs the code, and that the listener was registered before the page action. A page’s own console.log() does not automatically print in Node.js.
  • You see a message but cannot tell its category: print msg.type() alongside msg.text(); the text alone may not make the console method category obvious.
  • You cannot locate the source: inspect msg.location(), or use msg.stackTrace() when you need the message’s stack locations.
  • Formatted text is not enough: inspect msg.args() to access the console call’s arguments. Their exact remote-object representation can depend on the Puppeteer version.
  • The failure is not represented by a console event: investigate the relevant layer instead—page execution, Node.js, protocol traffic, browser process output or networking. Console events alone do not establish that those layers are healthy.

Version considerations

Puppeteer’s official documentation surfaces API pages for different versions: the current API pages reviewed identify Puppeteer 25.12.0, while related ConsoleMessage references surfaced 25.3.0 and 25.0.4. Documentation pages can advance independently, and no publication dates were displayed for the relevant pages. Confirm method availability and behavior against the Puppeteer package version in your project.

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

Or skip the browser setup

If your goal is to obtain a website screenshot rather than inspect its JavaScript console, ScreenshotNeo offers a screenshot API and MCP server. It does not read or forward Puppeteer console messages; it is a separate option for capturing a page. One GET request can return an image or PDF. For example, this cURL call saves a WebP screenshot of Stripe:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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. Before capture, it can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups and chat widgets; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

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

Frequently Asked Questions

Does Puppeteer emit a separate event for each console method?

The documented page event is named console; inspect msg.type() to distinguish the console method category.

Where can I check the exact ConsoleMessage methods for my installed Puppeteer release?

Use the official API reference and verify it against the version of the Puppeteer package installed in your project.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.