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 desk3 min

How to Close a Puppeteer BrowserContext

Await context.close() to dispose of a separately created Puppeteer BrowserContext and its associated pages; use browser.close() or disconnect() for different scopes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call and await context.close() to close a Puppeteer BrowserContext and every page associated with it. It returns a Promise<void>. The default browser context cannot be closed; this method is for a context you created separately.

Close a context and its pages

Create a separate context, open pages in it, and close the context when that work is finished:

As an Amazon Associate I earn from qualifying purchases.

const context = await browser.createBrowserContext();
const page = await context.newPage();

try {
  await page.goto('https://example.com');
  // Do work with the page.
} finally {
  await context.close();
}

The finally block makes the cleanup run whether the work completes normally or throws an error. Since closing the context also closes its associated pages, you do not need to call page.close() first when you intend to close the whole context. Close an individual page instead when you want the context and its other pages to remain open. See Puppeteer’s BrowserContext.close() reference.

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

What happens to cookies and storage?

A newly created browser context is isolated from other contexts: it does not share cookies or cache, and its cookies and local storage are separate. Closing it disposes of the context and its pages. Puppeteer’s BrowserContext class reference and createBrowserContext() reference describe those context properties and lifecycle.

Choose the right cleanup method

Call Effect Use it when
await context.close() Closes that context and all pages associated with it. You are finished with one separately created context.
await browser.close() Closes the browser and all associated pages. You are finished with the entire browser.
await browser.disconnect() Disconnects Puppeteer while leaving the browser process running. You want to detach Puppeteer without shutting down the browser.

These operations have different scopes; use the one that matches what should remain open. See Puppeteer’s Browser.close() and Browser.disconnect() references.

Common mistakes

  • Trying to close the default context: Puppeteer does not allow the default browser context to be closed. Create a separate context with browser.createBrowserContext() when you need a context you can dispose of.
  • Closing the browser when only one context should end: browser.close() shuts down the browser and all associated pages. Use context.close() for context-scoped cleanup.
  • Closing pages one by one before closing the context: This is unnecessary if the whole context is being disposed of. Close pages individually only if the context should stay open.
  • Disconnecting when you meant to stop the browser: browser.disconnect() leaves the browser process running; use browser.close() to close it.

Version note

The official API pages consulted report different Puppeteer documentation versions: the BrowserContext.close() page reports 25.9.0, the context class and creation pages report 25.12.0, and the browser close and disconnect pages report 25.10.0. These are not evidence that every page describes one identical release. If version-specific behavior matters, check the API documentation corresponding to the Puppeteer package installed in your project.

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
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 to get a website screenshot rather than manage a Puppeteer context, ScreenshotNeo can return an image or PDF from one API request. It is a different approach, not a way to close a Puppeteer context. For JavaScript, the supplied Node.js example is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

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

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
PC Slower Than It Used to Be?Free scan - under a minute
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.