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

How to Get the Page from a Puppeteer Console Message

Attach the console listener to a Puppeteer Page and use that captured Page inside the callback; ConsoleMessage does not expose a documented page accessor.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the Page instance that registered the 'console' listener. Puppeteer passes the callback a ConsoleMessage, but its documented API has no method that returns the originating page.

Use the Page listener’s closure

Register the listener on the page you want to monitor, then refer to that same page variable in the callback:

As an Amazon Associate I earn from qualifying purchases.

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

The Puppeteer PageEvent documentation describes the 'console' event as a page console API call and says it supplies a ConsoleMessage. The listener is attached to a particular Page, so the callback’s closure already has the page reference.

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

Identify messages from several pages or tabs

Attach a listener to each page and use its captured reference to label the output:

for (const page of pages) {
  page.on('console', msg => {
    console.log(`[${page.url()}] ${msg.type()}: ${msg.text()}`);
  });
}

Each const page binding in this loop belongs to its iteration. If your code is structured differently and the association is unclear, use a handler factory that accepts a page and returns its listener:

function logConsoleFor(page) {
  return msg => {
    console.log(`[${page.url()}] ${msg.type()}: ${msg.text()}`);
  };
}

for (const page of pages) {
  page.on('console', logConsoleFor(page));
}

What ConsoleMessage can and cannot tell you

The documented ConsoleMessage API lists methods for inspecting the console entry: args(), location(), stackTrace(), text(), and type(). It does not list a page accessor, and its constructor is marked internal.

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
  • msg.text() gives the message text; msg.type() gives its type.
  • msg.args() exposes the arguments passed to the console call.
  • msg.location() and msg.stackTrace() provide source-location information, not a Puppeteer Page.

For the Page event-listener pattern, see the Puppeteer Page API documentation.

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

Troubleshooting

  • The message has no page() method: That method is not part of the documented ConsoleMessage API. Capture the Page in the listener’s closure instead.
  • Several tabs produce indistinguishable logs: Install a separate listener on each page and include the captured page’s URL or another label in each log entry.
  • The displayed URL is not the URL you expected: page.url() reports the page’s URL when the callback runs. If navigation may have occurred, treat it as the page’s current URL, not necessarily the URL at the time the console call was made.
  • You need message details rather than page identity: Use msg.text(), msg.type(), msg.args(), or msg.location() for the console entry’s documented details.
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 website rather than inspect Puppeteer console output, ScreenshotNeo offers a one-request screenshot API. For example, with cURL:

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
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. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

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