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

Use userDataDir when browser data must persist in a directory between launches. Use browser.createBrowserContext() when jobs need separate, clean sessions inside one running browser. They are related but not interchangeable: a user-data directory is launch-time, directory-backed state; a browser context is an isolated session whose cookies, cache and local storage are kept apart from other contexts.

This guide shows both patterns, the launch settings that commonly affect profiles, lifecycle rules, failure recovery and an API alternative when your actual goal is simply obtaining reliable website screenshots.

Choose the kind of profile you actually need

Requirement Use What it means
Keep cookies and other browser data for later launches userDataDir A path supplied to puppeteer.launch(). Treat it as persistent browser data.
Run independent tasks in one browser process browser.createBrowserContext() Contexts do not share cookies or cache; the guide also identifies local-storage isolation.
Select a browser build or runtime behavior Launch options such as browser, channel, executablePath, args and headless These choose what is launched and how it runs; they are not substitutes for a persistent profile.

The LaunchOptions reference defines userDataDir as a path to a user-data directory. Pick a directory the process can read and write, and do not have competing browser processes use the same directory at the same time. That concurrency warning is operational guidance, not a documented locking guarantee.

Persist a Chrome profile with userDataDir

With a persistent directory, cookies, local storage and other browser-managed data can be available to a later launch that uses the same path. The path below is only an example; use an absolute path or a project-relative path appropriate for your deployment.

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.
#1 Best Overall
Sale
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    userDataDir: './my-browser-profile',
    headless: true
  });

  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });
    console.log('Title:', await page.title());
  } finally {
    await browser.close();
  }
})();

Run the program twice with the same directory to reuse the browser data. In CI, give each parallel worker its own directory (for example, a directory containing the worker ID) rather than sharing one profile. A profile can contain credentials and tokens, so protect its filesystem permissions and do not commit it to source control.

Keeping cookies between runs

  1. Launch with the same userDataDir path every time.
  2. Complete the login or consent flow once, then close the browser cleanly.
  3. On the next run, launch with that path before opening the page.

A persistent directory is not a guarantee that a site will accept an old session. Sites can expire or revoke cookies, require a fresh challenge, or bind sessions to other signals. Build a re-authentication path instead of assuming the profile is permanent.

Create isolated sessions with BrowserContexts

For parallel accounts, tests or untrusted tasks, create a context for each task. Puppeteer documents that browser contexts do not share cookies or cache, and its browser-management guide explicitly discusses local-storage isolation. In Chrome, non-default contexts are incognito contexts.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  const context = await browser.createBrowserContext();

  try {
    const page = await context.newPage();
    await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
    console.log(await page.title());
  } finally {
    await context.close();
    await browser.close();
  }
})();

Open every task page through its context. Popups opened by a page remain associated with that page’s context. Close the context when the task ends so its isolated state is discarded. This API creates isolated runtime state; do not describe it as a named, on-disk Chrome profile. The documentation establishes isolation, while userDataDir is the launch setting for a user-data directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere

Multiple clean sessions

const browser = await puppeteer.launch();
const contexts = await Promise.all([
  browser.createBrowserContext(),
  browser.createBrowserContext()
]);

try {
  const [a, b] = await Promise.all(contexts.map(async (context, i) => {
    const page = await context.newPage();
    await page.goto(i === 0 ? 'https://site-a.example' : 'https://site-b.example');
    return page.title();
  }));
  console.log({ a, b });
} finally {
  await Promise.all(contexts.map(context => context.close()));
  await browser.close();
}

Do not use one context when accounts must not see each other’s cookies or local storage. Conversely, do not create a new context when you need state to survive a later browser launch; use a directory-backed profile for that requirement.

Permissions and profile-related controls

Contexts can override permissions for an origin when a test needs deterministic behavior:

const context = await browser.createBrowserContext();
await context.overridePermissions('https://example.com', ['geolocation']);
const page = await context.newPage();

Remove or close the context after the test. Grant only the permissions the scenario requires.

Launch configuration also includes browser, channel, executablePath, args, headless, enableExtensions, extensionsEnabledInIncognito and Firefox’s extraPrefsFirefox. The current API reference surfaced for Puppeteer 25.12.0. Puppeteer guarantees its bundled browser; using a custom executablePath is at your own risk, so verify the browser/Puppeteer combination in your project before relying on it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Logitech M185 Compact Ambidextrous Wireless Mouse with Rubber Grips - Blue
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

Installation-level settings such as download and cache directories are covered by the Configuration interface. They affect package and browser installation, not the per-session state selected by userDataDir.

Lifecycle: close versus disconnect

await browser.close() shuts down the browser and its pages. Use it in a finally block for ordinary scripts, and close contexts before closing the browser when you created them explicitly. await browser.disconnect() only detaches Puppeteer; the browser and its pages continue running. Disconnect is useful when another process owns the browser lifecycle, but it can leave profile locks and processes behind if no owner eventually closes them.

Troubleshooting profile settings

“Profile is already in use” or launch failure

Another browser process is using the same directory, or a previous process crashed while holding a lock. Stop the owning process, confirm no worker still needs the profile, and retry. For parallel work, allocate one directory per process. Do not delete a profile while a browser is running.

Cookies do not persist

Confirm every launch uses the identical, writable userDataDir path. Check that your script reaches the login completion before closing and that the site has not expired the session. A context created inside a launch is not a replacement for a persistent directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
  • Computer mouse for easily navigating a computer interface; click, scroll, and more
  • USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
  • High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
  • 3 buttons offer effortless fingertip control
  • Plug-and-go ready for instant use

Contexts appear to share state

Make sure pages are created with context.newPage(), not browser.newPage() for every task. Inspect the context variable passed to each worker and avoid copying cookies or local-storage data intentionally between them.

Custom Chrome behaves differently

Check the selected channel or executablePath, headless mode and command-line arguments. Puppeteer only guarantees its bundled browser, and custom executables may differ in supported flags or behavior.

The process hangs on exit

Use finally to close pages, contexts and the browser. If you called disconnect(), remember that it does not terminate the remote browser; reconnect and close it, or stop it through the process manager that owns it.

Performance, reliability and security considerations

  • Startup: Reusing one browser and creating contexts is often operationally simpler than launching a process for every short task, while separate launches provide stronger process-level separation.
  • Disk growth: Persistent profiles accumulate caches, service-worker data and site storage. Monitor their size and periodically create a fresh profile when reproducibility matters.
  • Parallelism: Contexts simplify concurrent isolation inside one browser; persistent directories should be partitioned by worker.
  • Secrets: Treat profile directories as sensitive credentials. Restrict access, encrypt storage where appropriate and remove test profiles after use.
  • Reproducibility: Pin your Puppeteer version and verify the bundled browser revision. Recheck the API reference when upgrading, especially launch option types and browser compatibility.
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 you only need a website screenshot rather than an interactive, stateful browser session, ScreenshotNeo provides a one-call API. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.

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

cURL:

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

Python:

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)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for the remaining options, including full-page and element captures, device presets, dark mode, custom CSS/JavaScript, waiting rules, request blocking, cookies and headers, geolocation, PDFs, caching, signed links, asynchronous webhooks, bulk capture and usage reporting. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Best Value
Sale
Acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable 1600 DPI
  • 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
  • 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
  • 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
  • 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
  • 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.

FAQ

Can I name a BrowserContext and reopen it tomorrow?

No. A context is runtime isolation. Use a launch-time user-data directory when state must be available to a later browser launch.

Does --incognito replace createBrowserContext()?

Chrome’s non-default contexts are incognito, but the documented behavior of a launch argument and the context API should not be treated as identical for every user-managed Chrome profile.

Should I use browser.disconnect() after every task?

Only when another component owns the browser. Most standalone scripts should close the browser so pages and profile locks are released.

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

Frequently Asked Questions

Can a persistent profile be shared safely by parallel workers?

Use separate user-data directories per worker; sharing one directory creates locking and state-race risks.

Are browser installation settings the same as profile settings?

No. Configuration controls such as download or cache directories affect Puppeteer installation, while userDataDir selects browser user data for a launch.

Quick Recap

SaleBestseller No. 1
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Product carbon footprint: 3.97 kg CO2e; Contoured shape: Gives you more comfort and control
$14.90
SaleBestseller No. 3
Bestseller No. 4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Computer mouse for easily navigating a computer interface; click, scroll, and more; 3 buttons offer effortless fingertip control
$9.70

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.