Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

How to Get the Text of a Puppeteer Console Message

Listen for the Puppeteer page’s console event and call msg.text() for the message as a string. Use args() when you need the original logged values.
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 text() on the ConsoleMessage passed to the callback:

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

msg.text() returns a string. Use msg.args() instead when you need the original console arguments as separate values.

As an Amazon Associate I earn from qualifying purchases.

Read a console message’s text

Attach the listener to the Puppeteer Page instance. The callback receives a ConsoleMessage object, not a string, so call its text() method:

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.
page.on('console', msg => {
  console.log(msg.text());
});

Puppeteer emits the page’s console event for JavaScript console API calls; the event can also represent page errors or warnings. The official ConsoleMessage.text() reference documents the result as a string.

A complete minimal example, assuming page is already a Puppeteer Page, is:

page.on('console', msg => {
  const messageText = msg.text();
  console.log(messageText);
});

Choose the right message accessor

Use the accessor that matches what you need from the event. The ConsoleMessage class reference documents these message details:

Accessor What it provides Use it when
text() The message text as a string. You want to print, store, or compare the readable message.
args() The arguments passed to the console call. You need to inspect original values or objects individually.
type() The console message type. You need to distinguish message categories.
location() or stackTrace() Location or stack-trace information. You need context about where the message originated.

For example, this listener logs the text and type separately:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.on('console', msg => {
  console.log(`[${msg.type()}] ${msg.text()}`);
});

If page code logs several values or objects, use args() rather than expecting text() to return a structured array of those values. The two accessors serve different purposes.

Common mistakes and fixes

  • Logging the callback argument directly: the callback receives a ConsoleMessage, not the message text. Call msg.text().
  • Looking for original objects in text(): use msg.args() to access the console call’s arguments individually.
  • Trying to construct a ConsoleMessage yourself: its constructor is internal; consume the object Puppeteer sends through the event instead.
  • Expecting only ordinary log calls: the console event can also represent page errors or warnings. Check msg.type() if the category matters.
  • Attaching the listener to the wrong object: register it on the Puppeteer Page whose console activity you want to observe.

For current event and class details, see Puppeteer’s PageEvent documentation and ConsoleMessage reference.

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 the goal is a clean capture of a page rather than inspection of its console output, ScreenshotNeo takes a screenshot with one GET request. Its API can capture PNG, JPEG, WebP, or PDF; it is not a replacement for reading Puppeteer console messages.

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 options. Before capture, it accepts cookie or consent banners like a visitor and removes 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 are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

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

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

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.