The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
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.
#1 Best Overall
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
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Handle missing or surprising positions
- No URL:
urlmay beundefinedwhen 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 onConsoleMessage. - Version differences: API pages inspected for this article display different version labels: the
ConsoleMessageLocationinterface reference is labeled 25.3.0, while thelocation()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.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
Quick Recap
Best Value
Rank #4
- 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
Rank #3
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.




