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 desk3 min

Puppeteer Console Message Location Explained

Use msg.location() to read a Puppeteer console message’s optional source URL, zero-based line number, and column number.

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.

To find where a Puppeteer console message came from, call msg.location() on the ConsoleMessage received by the page’s console event. It returns an object with optional url, lineNumber, and columnNumber fields. The line and column values are zero-based, and either can be undefined when Puppeteer does not have that coordinate.

Get a console message’s source location

Register a listener for the page’s console event, then read the message location from the event argument:

page.on('console', msg => {
  const { url, lineNumber, columnNumber } = msg.location();
  console.log({
    type: msg.type(),
    text: msg.text(),
    url,
    lineNumber,
    columnNumber
  });
});

The event argument is a ConsoleMessage; location() returns a location object, not a formatted string. This API is documented in Puppeteer’s ConsoleMessage class reference. Puppeteer’s Page event documentation describes the console event as carrying a ConsoleMessage and lists the page events in the PageEvent reference.

What the location fields mean

Field Meaning What to handle
url URL of the resource associated with the message, when known. May be undefined; do not assume every message points to a resource URL.
lineNumber Zero-based line position in the resource, when known. May be undefined. Add 1 only if presenting it in a one-based display.
columnNumber Zero-based column position, when known. May be undefined. Convert deliberately if the consuming UI expects one-based positions.

The optional fields and zero-based coordinate convention are documented in the ConsoleMessageLocation interface. The pinned Puppeteer declarations in Chromium’s DevTools Frontend also show these optional properties: Puppeteer type declarations.

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

Why a location can be missing

A console message does not guarantee a known source coordinate. Treat url, lineNumber, and columnNumber as optional data: log or display whichever fields are present, and avoid arithmetic or string formatting that assumes a number or URL exists.

For example, to render a one-based line for a person while retaining Puppeteer’s original value for diagnostics:

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
page.on('console', msg => {
  const location = msg.location();
  const displayLine = location.lineNumber === undefined
    ? 'unknown'
    : location.lineNumber + 1;

  console.log({
    url: location.url ?? 'unknown',
    puppeteerLine: location.lineNumber,
    displayLine,
    columnNumber: location.columnNumber
  });
});

This conversion changes only the displayed line. Do not label a converted number as Puppeteer’s raw coordinate.

When to use location() versus stackTrace()

location() gives one primary source-location object. If that position is not enough to trace the message, use msg.stackTrace(), which is a separate method returning an array of locations on the message’s stack. The ConsoleMessage reference documents both methods; use the location object for a concise source reference and the stack array when you need additional stack locations.

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

What the console event captures

Puppeteer documents the Page console event for JavaScript console API calls such as console.log and console.dir; it is also emitted when the page throws an error or warning. Its payload is a ConsoleMessage. The event documentation is in the project’s PageEvent reference.

Version context

The live ConsoleMessage class reference displayed Puppeteer 25.12.0, while the ConsoleMessageLocation interface reference displayed documentation version 25.3.0. The documented optional fields and zero-based coordinate convention are consistent, but check the API reference and types for the Puppeteer version installed in your project, particularly if its version differs from those displayed documentation versions.

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
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 clean visual capture rather than tracing a JavaScript console message, ScreenshotNeo can return a screenshot or PDF from one GET request. It does not replace Puppeteer’s console-location API: use Puppeteer to inspect message coordinates. ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before a capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

cURL example, with the request options documented at ScreenshotNeo docs:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, 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. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.