Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
FREEDOM251

Freedom251 › Blog › browser automation

How to Get the URL of a Puppeteer Response

By Freedom251 Team · · 3 min read

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

Call response.url() on Puppeteer’s HTTPResponse object. For a navigation, check that page.goto() returned a response first; after redirects, that response represents the final URL.

Get the URL from an HTTPResponse

HTTPResponse.url() returns the URL of the response as a string. It is synchronous, so do not use await for this method.

As an Amazon Associate I earn from qualifying purchases.

const url = response.url();
console.log(url);

This works for an HTTPResponse you already have, including one received from a navigation or a response event.

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

Get the final URL after navigation

page.goto() resolves to the main resource’s HTTPResponse, or null in documented cases such as navigation to about:blank or to the same URL with only a hash change. Guard against null before calling url().

const response = await page.goto('https://example.com');

if (response) {
  console.log(response.url());
}

When a navigation follows redirects, page.goto() resolves with the response from the last redirect. Therefore, response.url() gives the final response URL, not necessarily the address originally requested. See the Puppeteer HTTPResponse.url() API and Page.goto() API.

Inspect the original request and redirect history

Puppeteer distinguishes the request URL from the response URL: HTTPRequest.url() returns a request’s URL, while HTTPResponse.url() returns the response URL. To inspect requests preceding the final response, get the response’s request and call redirectChain().

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
const response = await page.goto('http://example.com');

if (response) {
  console.log('Response URL:', response.url());
  const redirects = response.request().redirectChain();
  console.log('Redirected from:', redirects.map(request => request.url()));
}

The redirect chain contains earlier request objects; it is empty when there were no redirects. The final URL is still obtained from response.url(). See the HTTPRequest.url() API and HTTPRequest.redirectChain() API.

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

Handle null responses and HTTP error statuses

  • No response: A null result has no response URL. Check it before accessing response methods.
  • 404 or 500: An HTTP error status can still have an HTTPResponse. If you need to branch on success, inspect response.status(); do not treat the existence of a response as proof of a successful status.

For example:

const response = await page.goto('https://example.com/missing');

if (!response) {
  console.log('Navigation returned no response');
} else {
  console.log('URL:', response.url());
  console.log('Status:', response.status());
}

Troubleshoot common mistakes

  • response.url is not a function: Confirm that response is a Puppeteer HTTPResponse, rather than a URL string or another object.
  • Cannot read properties of null: page.goto() can return null in documented special cases. Add a null check before calling url().
  • The URL differs from the one passed to goto(): That is expected after redirects. Use response.url() for the final response and response.request().redirectChain() for earlier request URLs.
  • The page returned 404 or 500: A response may still be present. Read response.status() when status affects your logic.

Method documentation has appeared across Puppeteer versions; consult the documentation matching your installed version when checking version-specific behavior. The API references for HTTPResponse.url() and Page.goto() describe the relevant return values.

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 rather than inspecting a Puppeteer response, ScreenshotNeo returns a screenshot or PDF from one GET request. Its API removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. An MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

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. Sign up for 1,000 free screenshots a month, with no card required.

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.

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

browser automationJavaScriptPuppeteerWeb development

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
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.