Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon 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×
Skip to content
World desk3 min

How to Go Back to the Previous Page with Puppeteer

Learn how to call Puppeteer's page.goBack(), understand its nullable response, and handle missing history entries, SPA navigation, and timeouts.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await page.goBack() on a Puppeteer Page to navigate to the previous browser-history entry. It returns a promise that resolves to an HTTPResponse or null; if the page has no prior history entry, handle the rejection.

Call page.goBack()

Call the method after the page has navigated to a new history entry. Keep the returned value only if you need the main resource response:

As an Amazon Associate I earn from qualifying purchases.

const response = await page.goBack();

The return type is Promise<HTTPResponse | null>. Puppeteer documents null for same-page navigation; when redirects occur, the resolved response is for the last redirect. Puppeteer Page.goBack() reference

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

Complete example

This example opens a browser, visits one page, navigates to another, then goes back and closes the browser even if an operation fails:

import puppeteer from 'puppeteer';

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

  await page.goto('https://example.com');
  await page.goto('https://example.org');

  const response = await page.goBack();
  console.log(response); // HTTPResponse or null
} finally {
  await browser.close();
}

The first navigation gives the page a history entry to return to after the second navigation. Puppeteer’s Page documentation shows the launch, page creation, navigation, and browser-close lifecycle. Puppeteer Page class

History entries and single-page apps

“Previous page” means the preceding entry in the browser’s history, not necessarily a separate document loaded from the network. Puppeteer treats History API URL changes as navigation. In a single-page app, goBack() can therefore return to an earlier app state when the app created a history entry; it cannot return to a state that was never added to history. Puppeteer FAQ

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

Waiting and navigation timeouts

goBack() accepts optional wait options. Set the page’s default navigation timeout in milliseconds with page.setDefaultNavigationTimeout(timeout) when the normal navigation limit does not fit your flow. Puppeteer setDefaultNavigationTimeout() reference

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.setDefaultNavigationTimeout(30_000);
await page.goBack();

Choose the wait behavior and timeout for the page you are automating. A timeout or failed navigation should be handled as an error rather than treated as a successful return.

Handle missing history and other failures

  • No previous entry: When the page has no prior history entry, goBack() throws. Catch the rejected promise if your flow may reach that state.
  • Navigation timeout: Adjust the wait options or default navigation timeout to match the page’s behavior, and handle a timeout rejection.
  • Unexpected null: Do not assume a response object is always returned. Same-page navigation can resolve to null.
  • Unexpected destination in an SPA: Check that the app actually added the expected History API entry before calling goBack().
try {
  const response = await page.goBack();
  if (response === null) {
    console.log('Navigation did not produce a main-resource response.');
  }
} catch (error) {
  console.error('Could not go back:', error);
}

Protocol compatibility

Puppeteer’s WebDriver BiDi compatibility page lists Page.goBack() as fully supported. Chrome uses CDP by default unless BiDi is selected; Firefox uses BiDi by default. Since protocol support can vary by Puppeteer version, check the compatibility information for the version and protocol in your project. Puppeteer WebDriver BiDi support

Or skip the browser setup

If you need a screenshot rather than browser-history control, ScreenshotNeo returns an image or PDF with one GET request. For example, this cURL request saves a WebP screenshot of Stripe:

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
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 API options. Cookie banners, popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are not billed. An 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 ScreenshotNeo’s free plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does page.goBack() return an HTTP response every time?

No. It resolves to an HTTPResponse or null; same-page navigation can return null.

What happens if Puppeteer has no earlier history entry?

The call throws, so catch its rejection if the page may have no entry to return to.

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 *

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.

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.