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 Read the Stack Trace of a Puppeteer Console Message

Use Puppeteer’s console event to inspect a ConsoleMessage. Learn what location() and stackTrace() return, and when to handle pageerror or a Node.js failure separately.

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.

Listen for the page’s console event, then inspect the message’s text(), type(), location() and stackTrace(). The key distinction: location() returns the console message location, while stackTrace() returns an array of locations on that message’s stack—not an Error.stack string. If the page threw an uncaught exception, inspect pageerror as well; if Puppeteer’s Node.js code failed, debug that process separately.

Capture console messages from the page

Browser-side console.log() output does not automatically appear in Node.js. Attach a listener to the Puppeteer Page and read the delivered ConsoleMessage:

As an Amazon Associate I earn from qualifying purchases.

page.on('console', msg => {
  console.log('type:', msg.type());
  console.log('text:', msg.text());
  console.log('location:', msg.location());
  console.log('stack trace:', msg.stackTrace());
});

This follows the documented event and accessors; the exact location values depend on the message and installed Puppeteer version. The listener is useful for seeing what the page reports, but the event alone does not diagnose the underlying cause.

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

Puppeteer’s debugging guide explains that client code runs in the browser, so calling console.* in client code will not directly log to Node.js.

Read the message fields without mixing them up

text() and type(): what was reported

text() returns the message text. type() returns its console-message category; documented categories include error, warn and trace. Treat the type as context for the message, not proof of a particular root cause. See Puppeteer’s console message type reference.

location(): the console message location

location() returns the location of the console message. Keep that meaning separate from the stack: the location accessor is not documented as a substitute for the full set of stack locations.

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

stackTrace(): an array of stack locations

stackTrace() returns ConsoleMessageLocation[], an array of locations on the console message’s stack. Inspect the entries as structured location objects, using the API types for the Puppeteer version installed. Do not treat the return value as a single string or assume it is equivalent to an Error.stack value. The stackTrace() API reference documents the return type; the ConsoleMessage class reference lists the message accessors.

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

args(): associated arguments

A ConsoleMessage also exposes args(). When the text alone does not explain what the page logged, inspect the arguments alongside the text, type and location data rather than assuming the message text contains every useful detail.

Choose the event that matches the failure

What you are investigating What it represents Puppeteer path
Console output Page code called a console API; inspect the delivered message. page.on('console'), then text(), type(), location() and stackTrace().
Uncaught page exception An exception escaped in browser page code. page.on('pageerror').
Node.js-side failure The Puppeteer script or other server-side code failed. Use Node.js debugging and server-side logging.

Puppeteer’s PageEvent reference describes console as firing when page JavaScript calls a console API, and notes that it is also emitted if the page throws an error or warning. The same reference distinguishes pageerror for an uncaught page exception. For that reason, do not rely on a console-message stack alone when the question is specifically about an uncaught runtime exception.

Decide which execution context to debug

Before interpreting locations, determine where the problem occurs. A message captured from the page’s console listener follows the browser-side path. An error in the Node.js script or server code belongs to the Node.js-side path, even if the script launched the browser. Puppeteer’s debugging guide discusses Node.js server code, browser client code and, in some cases, browser-internal code as distinct places to investigate.

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
  • If page JavaScript explicitly logged a message, inspect the ConsoleMessage fields.
  • If an exception was uncaught in the page, also attach a pageerror listener.
  • If the automation script itself failed, inspect the Node.js error and debug the server-side code instead of expecting a page console event to explain it.
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 capture a page rather than debug its JavaScript, ScreenshotNeo offers a website screenshot API and MCP server for developers. One GET request can return a screenshot or PDF. For example, this cURL request saves a WebP screenshot:

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 documentation for API options. It removes cookie and consent banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are never billed; and its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.