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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

Puppeteer BrowserContext: Isolated Browser Sessions Explained

Puppeteer BrowserContext separates cookies, localStorage, and cache across browser contexts. Learn the current API workflow, lifecycle, and default-context differences.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

BrowserContext lets Puppeteer keep browser storage for one automation task separate from storage in other contexts. Create one with browser.createBrowserContext(), open task pages with context.newPage(), then close the context to close its pages and finish that session. This is storage isolation inside a browser instance—not a separate browser process or a complete security boundary.

What a Puppeteer BrowserContext isolates

A BrowserContext represents an individual user context. Puppeteer documents context-level separation for cookies, localStorage, and cache: one context does not share these items with other contexts. That makes contexts useful when separate test cases or automation tasks need separate browser state. See the BrowserContext API reference and createBrowserContext() reference.

“Isolated session” is a practical shorthand for this storage separation. The documentation does not establish that each context runs in a separate operating-system process or provides a complete security boundary. Do not rely on contexts alone to isolate mutually hostile workloads.

Create, use, and close a context

In current Puppeteer, create a context from the browser, create pages from that context, and close the context when the task is done:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const context = await browser.createBrowserContext();
try {
  const page = await context.newPage();
  await page.goto('https://example.com');
  // Run this task's checks or automation here.
} finally {
  await context.close();
}

This snippet assumes browser is an already launched Puppeteer browser. The finally block ensures that the context is closed even if navigation or a test fails. Closing a non-default context closes its associated pages too; the browser management guide demonstrates the context lifecycle.

Choose the page-creation method deliberately

  • browser.newPage() creates a page in the browser’s default context.
  • context.newPage() creates a page in the particular context you selected.

Use the default context when a task does not need storage separation or a group of pages to be closed together. Use an explicit context when you want a task’s storage separated from other contexts and want to dispose of its pages as a unit.

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

How pages, popups, and the default context relate

A launched browser has at least one default context. A context can contain multiple pages, and a page opened with window.open belongs to its parent page’s context. A popup therefore does not automatically start a fresh isolated context. The Page.browserContext() API reference describes how to identify the context that owns a page.

The default context cannot be closed. Close contexts your code creates rather than assuming every context returned by browser inspection is disposable. In Chrome, non-default contexts are incognito. The default context may also be incognito if Chrome was launched with --incognito, so “default” does not always mean “non-incognito.” These details are documented in the BrowserContext reference and close() reference.

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

Inspect open contexts

Use browser.browserContexts() to retrieve the browser’s open contexts. A newly created browser returns a single context from this method; that context is the default one. The method is documented in the browserContexts() API reference.

Work with cookies in the right scope

When a test uses a non-default context, use that context’s cookie methods so the operation applies to the session under test. BrowserContext provides methods such as cookies(), setCookie(), and cookie deletion methods. Puppeteer’s cookies guide explains reading, setting, and deleting browser cookies, including the relationship between browser-level methods and methods for a particular context.

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

Page-level cookie methods are deprecated in favor of the Browser or BrowserContext APIs in the current Page API reference. For new code, prefer the context-level methods when managing cookies for an explicitly isolated task.

Choosing between the default context and a new context

Approach Storage separation Cleanup Typical use
browser.newPage() Uses the default context; it does not create a separate context for the task. Close the page individually; the default context itself cannot be closed. A page that can share the default context’s browser state.
browser.createBrowserContext() then context.newPage() Uses a new context with cookies, localStorage, and cache separated from other contexts. Close the context to close its associated pages together. A task or test that needs separate browser storage and grouped cleanup.

Puppeteer’s documentation does not provide a numeric performance comparison between these approaches. Choose based on storage and lifecycle needs, not an assumed speed advantage.

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

Version note: use the current method name

Older examples may call browser.createIncognitoBrowserContext(). Puppeteer 22.0.0 renamed that method to browser.createBrowserContext() as a breaking change; the changelog dates the release entry to 2024-02-05. Current examples should use createBrowserContext(). See the Puppeteer changelog.

Troubleshooting context behavior

  • State appears shared: Check whether both pages were created with browser.newPage(), which uses the default context, rather than with separate calls to context.newPage().
  • A popup has the opener’s cookies: That is expected when it was opened with window.open; it belongs to the parent page’s context. Create a separate context explicitly if the task requires separate storage.
  • Closing a context closes several pages: This is expected behavior for its associated pages. If the pages need independent lifetimes, organize them into different contexts.
  • Closing the default context fails: The default context cannot be closed. Close only the non-default contexts created for individual tasks.
  • An example says the method does not exist: If it uses createIncognitoBrowserContext(), it may target an older Puppeteer API. For current Puppeteer, use createBrowserContext().
  • Cookie changes affect the wrong session: Use the cookie methods on the BrowserContext that owns the page, rather than relying on default-context or deprecated Page-level methods.

Or skip the browser setup

If the task is simply to obtain a website screenshot rather than automate browser behavior, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. For example, this cURL call saves a WebP screenshot; see the ScreenshotNeo documentation for request options:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo 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, and 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.

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. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
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.