Use message.location() inside Puppeteer’s console event handler to get a console message’s source location. The returned object has optional url, lineNumber, and columnNumber properties; line and column numbers are zero-based, and any value may be unavailable.
Read a console message’s source location
Puppeteer sends console messages through the page’s console event. Call location() on the event’s ConsoleMessage object to retrieve its location:
page.on('console', message => {
const location = message.location();
console.log({
text: message.text(),
url: location.url ?? '(unknown URL)',
lineNumber: location.lineNumber ?? '(unknown line)',
columnNumber: location.columnNumber ?? '(unknown column)',
});
});
location() returns a ConsoleMessageLocation. The url identifies the resource when known. The two numeric fields identify positions in that resource when known. Because all three fields are optional, check for missing values rather than assuming every message has a complete source location.
What the location fields mean
| Property | Meaning | When it may be absent |
|---|---|---|
url |
The URL of the resource associated with the message, if known. | It may be undefined when the resource is unknown. |
lineNumber |
The resource line number, if known. It is zero-based: line 0 is the first line. | It may be undefined when the position is unknown. |
columnNumber |
The resource column number, if known. It is zero-based: column 0 is the first column. | It may be undefined when the position is unknown. |
These property names and semantics are documented in Puppeteer’s ConsoleMessageLocation API reference. Treat the values as source coordinates, not human-counted positions beginning at one. If you display them to people who expect one-based numbering, convert only for display and preserve the original values for code or tooling.
#1 Best Overall
Handle missing fields safely
Optional properties can be absent independently. For example, a message may provide a URL but no line or column, so avoid a check that treats the location as all-or-nothing:
page.on('console', message => {
const { url, lineNumber, columnNumber } = message.location();
const source = url ?? '(unknown source)';
const position =
lineNumber === undefined
? '(unknown position)'
: columnNumber === undefined
? `line ${lineNumber}`
: `line ${lineNumber}, column ${columnNumber}`;
console.log(`${source}: ${position}: ${message.text()}`);
});
This keeps a known URL useful even when Puppeteer cannot supply coordinates. It also avoids confusing a valid zero with a missing value: use explicit undefined checks or nullish coalescing, not a truthiness test such as if (lineNumber).
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
TypeScript shape
The interface is equivalent in use to an object with three optional properties:
type ConsoleMessageLocation = {
url?: string;
lineNumber?: number;
columnNumber?: number;
};
For TypeScript code, let the installed Puppeteer types determine the exact exported type name and import path for your version. The important runtime behavior is that the location fields may be missing and the coordinates are zero-based.
Recommended Free Tools
Rank #3
Version note
The consulted Puppeteer API pages do not show synchronized version labels: the ConsoleMessageLocation reference displays version 25.3.0, while the ConsoleMessage.location() reference displays 25.12.0. The interface page documents the property meanings; the method page documents the return value. Check the references matching the Puppeteer version installed in your project before relying on version-specific details.
The method reference describes location() as “The location of the console message” and identifies its return type as ConsoleMessageLocation: ConsoleMessage.location() API reference. Puppeteer also notes that ConsoleMessage is internally constructed; third-party code should not construct or subclass it. Receive instances from the page event instead, as in the examples above: ConsoleMessage class reference.
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
Troubleshooting
locationis not a function: Confirm that the value comes from Puppeteer’spage.on('console', message => ...)callback. A plain object or a message from a different library may not be a PuppeteerConsoleMessage.- The URL or coordinates are undefined: This is allowed by the API. Keep the message text, report the known fields, and use an “unknown” label for unavailable values rather than treating the event as malformed.
- The reported line or column looks one too small: Puppeteer numbers both from zero. Add one only when presenting a human-facing, one-based display; do not change the underlying location data.
- The property or method differs from an example: Verify the installed Puppeteer version and consult its corresponding API reference. The inspected interface and method pages carry different version labels.
Or skip the browser setup
If your goal is to capture a webpage rather than inspect browser console events, ScreenshotNeo provides a screenshot API and MCP server. Its one-request example returns a screenshot file:
Quick Recap
Best Value
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. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →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.

