ScreenshotNeo

BlogHow-to

How to Get the Browser from a Puppeteer BrowserContext

Call `context.browser()` to get the Browser associated with a Puppeteer BrowserContext. It returns synchronously, so you do not need `await`.

By the ScreenshotNeo team4 October 20264 min read

Call context.browser() to get the Browser associated with a Puppeteer BrowserContext:

const browser = context.browser();

This method is synchronous: it returns a Browser, not a promise, so do not add await. It gives you the browser instance already associated with the context; it does not launch another browser. See the official BrowserContext.browser() reference.

Runnable example

This ES module launches Puppeteer, creates an isolated context and page, retrieves the associated browser, then closes the context and browser:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const context = await browser.createBrowserContext();
  try {
    const page = await context.newPage();
    await page.goto('https://example.com');

    const sameBrowser = context.browser();
    console.log(sameBrowser === browser); // true for this context
  } finally {
    await context.close();
  }
} finally {
  await browser.close();
}

The equality check follows from the context’s documented association with its browser. It is a useful sanity check in this example, rather than a separate guarantee about every possible wrapper or test setup. A context can be created with browser.createBrowserContext(), and pages within it with context.newPage(); see the BrowserContext reference.

Getting the browser when you start with a Page

If you have a Page instead of a context, get its context first, then its browser:

const browser = page.browserContext().browser();

page.browserContext() returns the context the page belongs to. browserContext() and browser() are synchronous accessors, so this expression does not need await. See the official Page.browserContext() reference.

What the returned Browser represents

A Browser represents the browser instance launched with Puppeteer or connected to with puppeteer.connect(). A BrowserContext is an individual user context within that instance. Contexts isolate storage such as cookies and local storage, so multiple contexts can belong to one browser while keeping their session data separate. Calling context.browser() returns the associated instance; it does not create a new browser or a new context. See the Browser reference and BrowserContext reference.

Return type and async behavior

Expression Result Use await?
context.browser() Browser No
page.browserContext() BrowserContext No
browser.createBrowserContext() A promise for a new context Yes
context.newPage() A promise for a new page Yes

The distinction matters: creating resources is asynchronous, while these accessors return objects that already exist. The documented signature for BrowserContext.browser() is browser(): Browser.

Common mistakes and troubleshooting

Symptom Cause Fix
await context.browser() appears to work but confuses the code await is unnecessary because the method returns a Browser directly. Use const browser = context.browser();.
Trying to call browser() on a Page The method belongs to BrowserContext. Use page.browserContext().browser().
Using browser.browserContexts() to get the browser That method lists contexts belonging to a browser; it does not retrieve the browser from a context. Call context.browser() when you have a context.
A context or its pages are already closed Closing a context closes that context and its associated pages; using objects after closing them may fail for later operations. Retrieve and use the browser while managing the owning browser’s lifecycle. Close contexts and the browser when finished.
Attempting to close the default context Puppeteer documents that the default browser context cannot be closed. Close contexts you created separately; close the browser when the whole browser instance should shut down.
Signature differs from an online example The docs may describe a different Puppeteer release than the installed dependency. Check the API reference for your installed Puppeteer version and its TypeScript declarations.

Lifecycle, reliability, and performance

  • Ownership: the context is associated with an existing browser. Getting that browser is an accessor, not a launch or connection operation.
  • Cleanup: context.close() closes that context and its pages. browser.close() shuts down the browser instance, so do not close it while other contexts or pages still need it.
  • Context isolation: use separate contexts when workflows need separate cookies or local storage while sharing one browser instance.
  • Cost: context.browser() itself creates no browser and performs no navigation. Resource and hosting costs come from launching or connecting to the browser and running pages, not from this synchronous lookup.
  • Version reliability: the method is documented in Puppeteer’s API. If behavior or types appear inconsistent, match the reference to the version in your project.

Or skip the browser setup

If your goal is simply to capture a website screenshot, ScreenshotNeo provides a screenshot API and MCP server for developers. One GET request returns an image or PDF without requiring you to launch and manage Puppeteer for that capture. See the ScreenshotNeo API documentation.

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

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await require('node:fs/promises').writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
  • Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
  • An MCP server lets AI agents using Claude, Cursor, or any MCP client take screenshots, get page information, and capture PDFs.
  • The Free plan includes 1,000 screenshots a month with no card. Paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month, with no card required.

FAQ

Does context.browser() launch a browser?

No. It returns the browser already associated with that context.

Can several contexts share one Browser?

Yes. A browser can own multiple contexts, which provide separate storage contexts within the browser.

Can I get the browser from a page?

Yes. Call page.browserContext().browser().

Can the default browser context be closed?

No. Puppeteer documents that the default context cannot be closed. Close the browser itself when you need to end that browser instance.