DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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×
FREEDOM251

Freedom251 › Blog › browser automation

How to Check the Type of a Puppeteer Console Message

By Freedom251 Team · · 2 min read

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 msg.type() on the ConsoleMessage Puppeteer passes to the handler. It returns the message category as a string, such as error, warn, or log.

Read a console message’s type

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

Puppeteer emits a ConsoleMessage through the page’s console event. Use that event-provided object; the ConsoleMessage class reference marks its constructor as internal, so application code should not create these objects directly.

As an Amazon Associate I earn from qualifying purchases.

To branch on a category, compare the return value with a supported type string:

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

  if (type === 'error') {
    console.error('Page console error:', text);
  }
});

This reports browser-page console messages. It does not, by itself, capture every kind of page failure, such as failed network requests; those require their corresponding Puppeteer events.

What values can type() return?

The Puppeteer ConsoleMessageType reference, labeled version 25.3.0, documents these strings:

  • log, debug, info, warn, error, verbose
  • dir, dirxml, table, trace, clear, assert
  • startGroup, startGroupCollapsed, endGroup
  • profile, profileEnd, count, timeEnd

For portability, check the type reference that matches the Puppeteer version installed in your project. The documented union is versioned API surface; do not assume another release has exactly the same list.

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

Choose the right inspection method

type() answers what category Puppeteer assigned. Other methods on the same event object expose different information, as listed in the class reference:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • text() returns the rendered message text.
  • args() exposes the arguments passed to the console call.
  • location() provides source-location information.
  • stackTrace() provides stack-trace information.

For example, log the category and text together when you need readable diagnostic output. Inspect arguments or source context when the rendered text alone is insufficient.

Troubleshoot common mistakes

  • Getting message text instead of its category: call msg.type(); msg.text() is for the rendered message.
  • Listening on the wrong event: register a console listener on the Puppeteer page to receive ConsoleMessage objects.
  • Only handling three familiar values: the documented type union includes additional categories such as table, assert, and verbose.
  • Constructing a message in application code: use the object Puppeteer emits; its constructor is documented as internal.
  • A type comparison does not match: compare the returned string with the documented literal, including capitalization, and confirm the type list for your installed Puppeteer version.
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 a screenshot rather than inspecting Puppeteer console events, ScreenshotNeo can return a page capture with one GET request. The API accepts a URL and can return PNG, JPEG, WebP, or PDF. Its cleanup can accept cookie/consent banners and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and whether the request was billed. ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

Install no browser automation for this call; create an API key and replace the example URL as needed. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free and get 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

browser automationDebuggingJavaScriptPuppeteer

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
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.