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

You cannot get a Puppeteer Page directly from a ConsoleMessage: the documented message methods do not include a page accessor. Instead, attach the console listener to the Page you want to monitor and use that same page reference inside the callback.

Use the Page that emitted the event

Puppeteer emits the console event on a Page and passes a ConsoleMessage to the listener. Since you register the listener on a specific page, the callback can close over that page reference:

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

Here, page is the Puppeteer Page; msg is the console message. This is the supported way to associate a message with its tab. The Puppeteer PageEvent documentation describes the event and its payload, and the Page API documentation shows Page event-listener usage.

Track messages from multiple pages or tabs

Install a separate listener on each page. Each callback then retains the page it belongs to, so its output can be labeled correctly:

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

With const in the loop, each iteration has its own page binding. If the surrounding code makes that relationship hard to follow, a handler factory makes it explicit:

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

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

Register the handler on every page whose console output you need to monitor; a listener on one page does not identify messages emitted by other pages.

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

What ConsoleMessage can and cannot tell you

The documented ConsoleMessage API provides methods for inspecting the console entry, but none returns the originating Page:

  • text() returns the message text.
  • type() returns its type.
  • args() returns the arguments passed to the console call.
  • location() reports the message’s source location.
  • stackTrace() returns locations in the message stack.

The constructor is marked internal. Use the page captured by the listener for page identity; use the message methods for message details. In particular, location() is a source location, not a reference to a Puppeteer page.

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

Troubleshoot page identification

  • The message object has no page() method: that is not a documented ConsoleMessage accessor. Refer to the page on which you registered the listener.
  • Several tabs show indistinguishable log lines: add a page-specific label, such as page.url(), inside each listener, as in the examples above.
  • A handler appears to log the wrong page: check that each page gets its own listener and that the callback closes over that iteration’s page. Use const per loop iteration or the handler-factory pattern.
  • You expected msg.location() to identify the tab: it gives the console entry’s source location. It does not identify the emitting Page.
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 you need a clean capture of a page rather than Puppeteer console-event handling, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns an image or PDF; see the API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers report the page verdict and billing status.
  • Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents, including Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month with no card.

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

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.