Listen for the page’s console event, then call msg.location() on the ConsoleMessage object. It returns an object with the message’s URL, line number, and column number when Puppeteer knows them; each field can be undefined.
Capture the URL, line, and column from a console event
Browser-side console.* output does not appear in Node.js automatically. Puppeteer exposes it through the page’s console event. Register a listener before the page runs the code whose output you want to inspect:
As an Amazon Associate I earn from qualifying purchases.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
page.on('console', msg => {
const location = msg.location();
console.log({
text: msg.text(),
url: location.url,
lineNumber: location.lineNumber,
columnNumber: location.columnNumber,
});
});
await page.goto('https://example.com');
// Trigger or wait for the page's console output here.
} finally {
await browser.close();
}
})();
The essential call is msg.location(). The returned value is a structured object, not a formatted string. Its documented fields are url, lineNumber, and columnNumber. See the Puppeteer ConsoleMessage API reference and the ConsoleMessageLocation interface.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Handle missing metadata
The location fields are optional. If a value is unavailable, preserve that fact rather than logging it as a confirmed source coordinate. Line and column numbers are zero-based; add one only when presenting them to people in a one-based editor or display, not when passing the original values to tooling.
#1 Best Overall
page.on('console', msg => {
const {url, lineNumber, columnNumber} = msg.location();
console.log(msg.text(), {
url: url ?? '(unknown URL)',
lineNumber,
columnNumber,
});
});
Choose between location() and stackTrace()
Use location() for the compact source coordinates associated with the message. Use stackTrace() when you need the array of locations on the message’s stack:
page.on('console', msg => {
const frames = msg.stackTrace();
console.log(msg.text(), frames);
});
The API describes stackTrace() as returning an array of locations, but does not guarantee that the array is populated for every message. Check it before relying on a frame:
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
page.on('console', msg => {
const frames = msg.stackTrace();
const firstFrame = frames[0];
console.log({
text: msg.text(),
firstFrame: firstFrame ?? null,
});
});
For everyday structured logs, the single optional location object is usually the simpler choice. For investigating additional stack locations, inspect the array and handle the case where it has no entries. See the stackTrace() API reference.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesTell browser output apart from Node.js output
The page.on('console') listener captures console messages emitted by the browser page. It does not make Node.js console output part of the page’s console stream. When diagnosing a problem, identify which side produced the message before tracing its source.
Rank #3
If you need to step through browser execution interactively, Puppeteer’s debugging guide describes launching with devtools: true and using a debugger statement.
Troubleshoot missing or unexpected locations
url, line, or column is undefined: Treat it as unavailable metadata. The API permits undefined fields; inspectstackTrace()for other useful locations, while allowing for an empty array.- No browser message reaches the listener: Confirm that the listener is attached to the relevant
pagebefore the browser code runs, and that the message is emitted by the page rather than Node.js. - The displayed line or column appears off by one: Puppeteer’s values are zero-based. Convert to one-based numbering only for human-facing display; keep the original numbers for tools that expect API values.
- The URL is not the authored source you expected: A location identifies a resource location when available; the API documentation does not guarantee that it resolves to authored code rather than a generated resource.
Behavior is not fully specified in the cited API pages for every browser, protocol, source-map setup, or Puppeteer release. Check the reference for the version installed in your project before depending on version-specific behavior.
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
Or skip the browser setup
If you also need a page image rather than console coordinates, ScreenshotNeo is a website screenshot API; it does not replace Puppeteer’s console-event listener or return a console message’s source location. One GET request can capture a page:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Before a capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
Quick Recap
Best Value
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.




