Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Get the Current URL in Puppeteer

Puppeteer’s page.url() returns the main frame’s current URL synchronously. Learn when to wait for navigation and how to read an iframe URL.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s synchronous page.url() method to get the current URL of the page’s main frame:

const currentUrl = page.url();
console.log(currentUrl);

It returns a string; you do not need await. For an iframe, get its Frame and call frame.url() instead.

As an Amazon Associate I earn from qualifying purchases.

Get the main page URL

page.url() is a shortcut for page.mainFrame().url(), so it reports the URL of the main frame—not the URL of an embedded iframe. See the Puppeteer Page API.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const currentUrl = page.url();
console.log(currentUrl);

The call is synchronous. Add await only to the action or wait that must finish before you read the URL, not to page.url() itself.

Read the URL after navigation

If a click triggers a navigation, start waiting for that navigation at the same time as the click. Otherwise, the click could navigate before the wait is registered.

const [response] = await Promise.all([
  page.waitForNavigation(),
  page.click('a.my-link'),
]);

const currentUrl = page.url();
console.log(currentUrl);

waitForNavigation() resolves with the main-resource response, or null when there is no such response. You can still read the current URL with page.url() afterward. See the Puppeteer navigation API.

Single-page applications and History API changes

Puppeteer treats URL changes through anchor navigation and the History API as navigation, including changes made with pushState. Wait for the action or URL-changing operation to finish, then call page.url(). The same concurrent-wait pattern is useful when that operation is triggered by a click. See the Puppeteer navigation FAQ.

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.

Get a URL from an iframe

Use the relevant Frame object’s url() method. Identify the frame using a stable property of your application, such as a known URL pattern:

const frame = page.frames().find(frame => frame.url().includes('/embedded/'));
const frameUrl = frame?.url();

console.log(frameUrl);

page.frames() returns the page’s current frame tree, and Frame.url() returns the URL for that specific frame. The optional chaining above leaves frameUrl undefined if no matching frame is found; handle that case if your code requires a URL. See the Puppeteer Frame API.

Don’t confuse reading a URL with navigating

  • page.url() reads the main frame’s current URL.
  • frame.url() reads the URL of a specific frame.
  • page.goto(url) navigates to a URL; it is not a getter. It returns a response or null. In documented cases such as navigating to about:blank or changing only the URL hash, it can return null. See the Puppeteer Page.goto API.

Troubleshooting

The value is the old URL

You may be reading it before the navigation or URL-changing operation has completed. For a click that navigates, register waitForNavigation() alongside the click with Promise.all(), then call page.url().

The URL is for the page, not the embedded content

page.url() returns the main frame URL. Find the relevant frame in page.frames() and use that frame’s url().

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

waitForNavigation() returned null

A null navigation response does not prevent checking the resulting URL. Read page.url() after the wait and action have completed.

The code says page.url is not a function

Check that page is the Puppeteer Page object returned by your browser or context setup, rather than a URL string or another object. Also check the Puppeteer documentation for the version installed in your project; the published API pages may describe different versions.

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 you need a screenshot rather than a Puppeteer-controlled browser page, ScreenshotNeo returns a capture from one GET request. For example, with cURL:

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 documentation for setup and options. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

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

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.

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.