October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Navigate to a URL with Puppeteer

A practical guide to Puppeteer URL navigation with page.goto(), wait conditions, timeouts, click-triggered navigation, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await page.goto('https://example.com') to navigate a Puppeteer page to a URL. Include the URL scheme, then choose a navigation wait condition that fits what you will do next; the default is to wait for the page’s load event.

Navigate with page.goto()

This complete JavaScript example launches Puppeteer, opens a page, navigates to a URL, and prints the main resource’s HTTP status when a response is available:

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  const response = await page.goto('https://example.com');
  console.log('HTTP status:', response?.status());
} finally {
  await browser.close();
}

The example uses ES modules and top-level await. Puppeteer’s getting-started guide also demonstrates importing either puppeteer or puppeteer-core; choose the package appropriate to your project and browser setup. See the official getting-started guide.

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.

page.goto() returns a promise for the main resource response. It can resolve to null for cases such as navigating to about:blank or changing only the hash on the same URL. An HTTP error status does not necessarily make navigation throw: inspect the returned response’s status when the result matters. Puppeteer’s documentation specifically notes that in headless shell, statuses such as 404 and 500 do not cause goto to throw. See the Page.goto API reference.

Choose when navigation should count as complete

goto accepts waitUntil to define the browser lifecycle event or events Puppeteer waits for. In the documentation version 25.12.0, the default is load; the default navigation timeout is 30,000 milliseconds. You can supply one event or an array, in which case all listed events must fire before the wait succeeds. These values are API defaults, not a guarantee that every page is ready for your next operation.

await page.goto('https://example.com', {
  waitUntil: 'domcontentloaded',
  timeout: 45_000,
});

This illustrative call waits for domcontentloaded and allows 45 seconds for the configured completion condition. Pick a condition based on what follows: a lifecycle event may be enough for one task, while an application-specific element may be a better signal for another. The API also documents timeout: 0 as disabling the timeout; use it only when you deliberately want navigation to have no time limit. Check the WaitForOptions reference for the version your project uses.

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

Set a navigation timeout

Use the timeout option in a goto call to tune that navigation. To change the default limit for a page’s navigation operations, call page.setDefaultNavigationTimeout(milliseconds):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.setDefaultNavigationTimeout(45_000);
await page.goto('https://example.com');

The default navigation timeout applies to goto, waitForNavigation, reload, and related methods. Prefer a per-call timeout when only one navigation needs different handling; use the page-level setting when the same limit should govern navigation calls on that page. See the setDefaultNavigationTimeout API reference.

Wait for navigation caused by a click

When a link or button triggers a new navigation, register the navigation wait before clicking. Use Promise.all so the wait is already active when the click occurs:

const [response] = await Promise.all([
  page.waitForNavigation(),
  page.locator('a.next').click(),
]);

console.log('HTTP status:', response?.status());

Starting the click first and waiting afterward risks missing a fast navigation. waitForNavigation() returns the main resource response for ordinary navigation, but may return null for a different anchor or a History API navigation. History API URL changes count as navigation. See the waitForNavigation API reference and Puppeteer’s documented click-and-wait pattern.

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

Wait for the page content your task needs

A navigation lifecycle event tells you something about loading; it does not prove that a specific application element is ready. For interaction, Puppeteer recommends locators, which wait for element presence and action preconditions such as visibility, enabled state, and stable layout. After navigation, act on the locator for the content or control your task actually needs rather than assuming that the URL change alone is sufficient. See the page interactions guide.

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

Puppeteer’s official screenshot and PDF examples use waitUntil: 'networkidle2'. Treat that as an example workflow choice, not a universally best setting; choose the condition according to the target page and the operation that follows. See the screenshot guide and PDF generation guide.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot navigation failures

  • Invalid URL: Check that the address is valid and includes its scheme, such as https://.
  • Navigation timeout: Puppeteer did not observe the selected completion condition before the configured limit. Check whether the condition matches the task before increasing the timeout; use a per-call or page-level timeout as appropriate.
  • SSL error or unreachable server: Verify the target address and whether the server is reachable from the machine running the browser.
  • Main resource fails to load: Check the target’s response and browser/network conditions. Navigation can fail when the main resource does not load.
  • Navigation appears successful but the page is not usable: Wait for the relevant application element with a locator; lifecycle completion and application readiness are different conditions.
  • Navigation returns no response: A null response can be expected for same-document cases such as a hash-only change or History API navigation. Do not treat null alone as proof of a failed page load.
  • HTTP 404 or 500: Read the response status. In headless shell, a valid HTTP status such as 404 or 500 does not make goto throw.

Puppeteer lists invalid target URLs, SSL errors, timeouts, unreachable servers, and failures loading the main resource among navigation failure causes. See the HTTPError API reference.

Or skip the browser setup

If you only need a URL captured as an image or PDF, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request can return PNG, JPEG, WebP, or PDF. For an image capture, save the response body as a file:

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 documentation for API options. Cookie banners are accepted and removed before capture, along with supported consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

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

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Frequently Asked Questions

Which Puppeteer documentation version do these defaults refer to?

The documented navigation option defaults cited here are from Puppeteer documentation version 25.12.0; check the API reference for the version used by your project.

Can `page.goto()` return `null` without indicating an ordinary load failure?

Yes. Documented same-document cases include navigating to `about:blank` and changing only the URL hash; `waitForNavigation()` can also return `null` for anchor or History API navigation.

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.

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.