Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › browser automation

How to Get the URL of a Request in Puppeteer

By Freedom251 Team · · 3 min read

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

Listen for the page’s request event and call url() on the supplied request object:

page.on('request', request => {
  console.log(request.url());
});

This observes requests as the page makes them; you do not need request interception just to read or log their URLs.

As an Amazon Associate I earn from qualifying purchases.

Log request URLs in a working Puppeteer script

Register the listener before navigating so it can observe requests made during page load. The callback receives an HTTPRequest; its url() method returns that request’s URL as a string.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();

try {
  const page = await browser.newPage();

  page.on('request', request => {
    console.log(request.url());
  });

  await page.goto('https://example.com');
} finally {
  await browser.close();
}

This example uses an ES module import. Run it in a Node.js project configured for ES modules with Puppeteer installed. Replace the navigation URL with the page you want to observe. The output is one line per request event, so a page may produce URLs for its document, scripts, stylesheets, images, and other resources.

Filter for a particular request

Read the URL once in the callback, then apply your own condition. For example, to log URLs containing /api/:

page.on('request', request => {
  const url = request.url();
  if (url.includes('/api/')) {
    console.log(url);
  }
});

The substring is just an illustrative filter. You can use an exact match, a regular expression, or another request property according to what you need to identify. The URL returned by request.url() is a string.

Request URL and response URL are different observations

Use the event and object that match the point in the lifecycle you care about:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • page.on('request', request => ...) observes an outgoing request and exposes its URL through request.url().
  • page.on('response', response => ...) observes a response and exposes its URL through response.url().

For the URL of a request as the page issues it, use the request event. A response listener is useful when your code is specifically handling responses.

How redirects appear in the log

A redirect is represented as a successfully finished request followed by a new request to the redirected destination. Consequently, a request listener can log both the original URL and the destination URL as separate requests. Treat them as separate events rather than assuming one request object changes its URL in place.

When request interception is needed

Do not enable interception just to inspect URLs. Use page.setRequestInterception(true) when you need to modify, abort, or fulfill requests. With interception enabled, each request stalls until it is resolved—for example, by continuing, responding, or aborting it. A URL-only interception handler must still continue each request:

await page.setRequestInterception(true);

page.on('request', request => {
  console.log(request.url());
  request.continue();
});

If multiple handlers or asynchronous work may resolve the same intercepted request, check request.isInterceptResolutionHandled() before resolving it, and check again after awaiting. Another handler may have resolved it in the meantime. This extra resolution logic applies to interception workflows, not ordinary request-event logging.

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.

Troubleshooting

  • No URLs appear: Attach the listener before page.goto() and make sure the page actually initiates requests. The event reports requests made by that page.
  • Navigation hangs after enabling interception: Every intercepted request needs to be resolved. Continue requests you are not changing, or respond to or abort them as appropriate.
  • The same destination appears more than once: A page can issue multiple requests, and redirects can result in a new request for the destination. The event logs request events, not a deduplicated list of destinations.
  • You need the URL associated with a response: Listen for response and use response.url(); use request.url() when handling the outgoing request.
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 screenshot of a page rather than inspecting every network request, ScreenshotNeo can return an image or PDF with one GET request. It does not expose Puppeteer’s request-event log, so it is not a replacement when you need to collect request URLs.

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 parameters. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

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.

browser automationJavaScriptNode.jsPuppeteerweb automation

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.

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.