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

How to Set Cookies with Puppeteer Cookie Parameters

Use Puppeteer’s current browser or browser-context cookie setter, choose cookie scope and security fields for your test, then verify storage on the same context.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Browser.setCookie() for the default browser context or BrowserContext.setCookie() for a specific context, and pass each cookie as its own object argument. Puppeteer’s current documented cookie input is CookieData; the older Page.setCookie() API is marked obsolete. Set the cookie on the same context as the page that needs to send it.

Set a cookie before navigating

Create a browser context, set the cookie on that context, then create or use a page in that context. The example below uses an isolated context so its cookies do not belong to the default context.

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();

try {
  const context = await browser.createBrowserContext();

  await context.setCookie({
    name: 'session',
    value: 'example-value',
    domain: 'example.com',
    path: '/',
    httpOnly: true,
    secure: true,
    sameSite: 'Lax',
  });

  const page = await context.newPage();
  await page.goto('https://example.com');

  console.log(await context.cookies());
} finally {
  await browser.close();
}

This follows the current Puppeteer pattern of setting cookies through a browser or browser context rather than through a page. See the Puppeteer cookies guide and the BrowserContext API reference.

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

Use the intended context

A browser context isolates storage, including cookies. If the target page belongs to a context you created, call that context’s setCookie(). Calling browser.setCookie() instead writes to the default browser context, not the separate context. The corresponding read and delete operations are available on browser contexts as well.

Pass separate cookie objects, not an array

Both setters accept one or more cookie objects as arguments. For multiple cookies, pass them separately:

await context.setCookie(
  { name: 'session', value: 'example-value', domain: 'example.com', path: '/' },
  { name: 'preference', value: 'compact', domain: 'example.com', path: '/' },
);

Do not wrap the objects in an array as the sole argument. The official guide demonstrates multiple cookies in one call and reading them back afterward.

Choose cookie parameters deliberately

The current CookieData interface documents name and value as required. The fields below are optional; choose values based on the site and the requests you need to test, rather than applying one security policy to every cookie. Puppeteer’s surfaced reference is labeled v25.12.0; check your installed version and browser when relying on browser-specific fields.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Parameter Meaning and practical use
name, value Required cookie name and value.
domain Sets the cookie’s domain scope. Specify it when the cookie should apply to a particular domain.
path Sets the path scope. Use a path appropriate to the pages that should receive the cookie.
expires A numeric expiration date. Omit it for a session cookie; consult the installed version’s reference for the accepted representation and behavior.
httpOnly Use true when page JavaScript should not read the cookie.
secure Use true for a cookie intended to be sent only over HTTPS.
sameSite Controls the cookie’s SameSite behavior. Select the documented value appropriate to the navigation and request scenario you are testing.
priority Cookie priority; the reference documents this as Chrome-only.
sourceScheme Source scheme information; the reference documents this as Chrome-only.
partitionKey Partitioning information. The documented semantics vary by browser: the reference associates it with the top-level site in Chrome and describes source-origin matching for Firefox.

The current browser-level type is CookieData. A separate CookieParam reference belongs to the page-level API and includes a url field, which can affect default domain, path, and source-scheme values. Do not treat that legacy page-level input type as the preferred setter for current code.

Read and remove cookies

After setting a cookie, inspect the storage on the same context to verify that it was accepted:

const cookies = await context.cookies();
console.log(cookies);

The official guide also demonstrates reading cookies through browser.cookies() for the default context. For cleanup, BrowserContext documents deleteCookie() and deleteMatchingCookies(); use the context that owns the cookie. The page-level cookie APIs are deprecated in favor of browser and context methods. See the Browser.setCookie(), BrowserContext, and Page.setCookie() references.

Common problems and fixes

  • The page does not receive the cookie: Confirm the cookie was set on the same context as the page, and check that its domain and path cover the destination URL.
  • The cookie appears absent after navigation: Read it back with context.cookies() and check its scope and security fields. In particular, an HTTPS-only cookie should be tested against an HTTPS URL.
  • Code passes an array to setCookie(): Pass cookie objects as separate arguments instead.
  • Code uses page.setCookie(): Replace it with context.setCookie() or browser.setCookie(), according to the page’s context. Puppeteer marks the page setter obsolete.
  • A browser-specific field has no expected effect: Check support in the installed Puppeteer and browser versions, especially for priority, sourceScheme, and partitioning.
  • A cookie disappears when the context is recreated: A cookie without expires is a session cookie; use an appropriate expiration when persistence is required.
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 capture a website rather than run browser automation yourself, ScreenshotNeo is a screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF; the API also offers options for cookie values and other browser settings. For the full parameter list, see the ScreenshotNeo documentation.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Which Puppeteer version should I check before using these fields?

Check the Puppeteer version installed in your project: the API reference labels surfaced for CookieData and BrowserContext are v25.12.0, while CookieParam is labeled v25.11.0. Those documentation labels do not establish which version your project uses.

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
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.