DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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

Puppeteer ConsoleMessageLocation: Get a Console Message’s URL, Line, and Column

Puppeteer’s message.location() returns an optional source URL, line, and column. Coordinates are zero-based, so handle missing values and account for them when formatting output.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use message.location() inside Puppeteer’s page.on('console', ...) handler to get a console message’s source location. The returned object can contain url, lineNumber, and columnNumber; each property is optional, and line and column numbers are zero-based.

Read a console message’s source location

Puppeteer emits console messages through the page’s console event. Call location() on the event’s message object:

As an Amazon Associate I earn from qualifying purchases.

page.on('console', message => {
  const location = message.location();
  console.log(location);
});

The returned ConsoleMessageLocation object describes where the message came from when Puppeteer knows that information. It is not guaranteed to include a URL or coordinates.

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

What the location fields mean

Property Type Meaning
url string or undefined The resource URL, if known.
lineNumber number or undefined The zero-based line number in the resource, if known.
columnNumber number or undefined The zero-based column number in the resource, if known.

Because coordinates start at zero, a reported line number of 0 means the first line, and a column number of 0 means the first column. Convert them to one-based values only when presenting them to readers or tools that expect human-counted positions.

Format locations defensively

Check each optional value before building a source label. This TypeScript example avoids printing undefined and makes the zero-based convention explicit:

import type { ConsoleMessageLocation } from 'puppeteer';

function formatLocation(location: ConsoleMessageLocation): string {
  const source = location.url ?? '<unknown source>';
  const line = location.lineNumber;
  const column = location.columnNumber;

  if (line === undefined) return source;
  if (column === undefined) return `${source}:${line} (zero-based line)`;
  return `${source}:${line}:${column} (zero-based)`;
}

page.on('console', message => {
  console.log(formatLocation(message.location()));
});

If your logger or issue tracker expects one-based coordinates, add one to each known number when formatting; do not change the values used internally unless that conversion is intended.

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

Handle missing or surprising positions

  • No URL: url may be undefined when the resource is unknown. Use a fallback label rather than assuming every message maps to a script URL.
  • No line or column: either coordinate may independently be undefined. Preserve the known portion of the location and avoid arithmetic or string formatting until you check it.
  • Off-by-one display: Puppeteer’s documented line and column values are zero-based. Add one only for user-facing display when required by your convention.
  • Event handler receives a message: obtain the location from that message with message.location(); the method is documented on ConsoleMessage.
  • Version differences: API pages inspected for this article display different version labels: the ConsoleMessageLocation interface reference is labeled 25.3.0, while the location() method reference is labeled 25.12.0. Match the documentation to your installed Puppeteer version rather than assuming those page labels are synchronized.

References and version notes

The Puppeteer ConsoleMessageLocation API reference describes the optional fields and zero-based coordinates (page labeled 25.3.0). The ConsoleMessage.location() reference documents the method returning that interface (page labeled 25.12.0). The ConsoleMessage class documentation describes dispatch through the page’s console event and notes that its constructor is internal; application code should consume event messages rather than constructing or subclassing them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 capture of a page rather than debugging its console events with Puppeteer, ScreenshotNeo is a website screenshot API and MCP server. A GET request returns a PNG, JPEG, WebP, or PDF. Cookie banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are not billed; and its MCP server lets AI agents take screenshots.

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

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.

Leave a Reply

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

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.

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