Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Puppeteer CookieParam: Set Cookies with Options

Set Puppeteer cookies with the current browser- or context-level API, and choose CookieParam fields for the scope, lifetime, and behavior your test needs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To set a cookie in current Puppeteer, pass an object containing the required name and value to browser.setCookie() or browserContext.setCookie(). Add optional fields such as url, domain, path, expires, and security attributes only when they match the cookie you need to represent. The current Puppeteer docs mark page.setCookie() obsolete.

Set a cookie with the current Puppeteer API

The simplest current example uses the browser’s default context:

As an Amazon Associate I earn from qualifying purchases.

await browser.setCookie({
  name: 'example',
  value: 'value',
  domain: 'localhost',
  path: '/',
});

Call it after launching Puppeteer and before navigating to the page that needs the cookie. The snippet assumes browser is an already launched Puppeteer browser; it sets a cookie for localhost, not for every website. Puppeteer’s BrowserContext.setCookie() reference documents the current cookie-setting method, and the cookies guide shows the equivalent browser-level method. The API references displayed Puppeteer version 25.12.0 when accessed on October 3, 2026.

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

For storage isolated to a particular browser context, use that context directly:

await context.setCookie({
  name: 'example',
  value: 'value',
  url: 'https://example.com/',
});

Here, context is the BrowserContext associated with the target page. Browser methods are shortcuts for the default context; use a specific BrowserContext when you want its cookie storage isolated from other contexts. See Puppeteer’s cookies guide.

What CookieParam fields can you set?

The CookieParam reference lists name and value as required. The other fields are optional. Their presence in the API does not mean every cookie needs them: choose values according to the cookie’s intended scope, lifetime, and browser behavior. Puppeteer’s CookieParam reference lists these options.

Purpose Fields How to choose
Identity and content name, value Both are required strings. Use the cookie name and value expected by the site or test.
Scope domain, path, url Set the scope to match the request or site behavior being tested. The url can affect default domain, path, and source-scheme values.
Lifetime expires Expiration date as a number; omit it for a session cookie.
Security and access httpOnly, secure, sameSite Represent the cookie’s intended HTTP-only, secure-connection, and SameSite behavior. Do not copy settings blindly from an unrelated example.
Partitioning and browser-specific behavior partitionKey, priority, sourceScheme partitionKey is a CookiePartitionKey or string. Its interpretation differs: Chrome matches the top-level site for the partitioned cookie; Firefox matches the source origin in the partition key. priority and sourceScheme are supported only in Chrome.

Choose scope, lifetime, and security attributes deliberately

Domain, path, or URL

Use domain and path when you need to state the cookie’s scope explicitly. Alternatively, provide url for the request URI associated with setting the cookie; Puppeteer documents that it can affect default domain, path, and source-scheme values. The right choice depends on the target site and the behavior under test, so a localhost example is not a universal configuration.

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

Session or expiration

If expires is omitted, the cookie is a session cookie. If the test needs a persistent cookie, provide an expiration date appropriate to that test. Avoid reusing a fixed expiration from a sample without checking whether it still matches the scenario.

HTTP-only, secure, SameSite, and partitioned cookies

httpOnly, secure, and sameSite describe meaningful cookie behavior and should reflect the case you are testing. For partitioned cookies, account for the browser-specific meaning of partitionKey. Chrome-only options are not portable assumptions for Firefox.

Why BrowserContext can be the better choice

Browser contexts isolate storage such as cookies and local storage. When tests need separate cookie states, create or select the intended context and call context.setCookie() rather than putting all state in the default context. The default Browser methods operate on that default context. Puppeteer describes the context-level method and its cookie isolation in the cookies guide.

Do not start new code with Page.setCookie()

The current Page.setCookie() API reference marks the page-level method obsolete and directs users to Browser.setCookie() or BrowserContext.setCookie(). Prefer one of those methods in new code rather than copying older examples that call page.setCookie().

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Documentation example: localhost cookies

Puppeteer’s guide demonstrates setting two localhost cookies with explicit values including expires: -1, httpOnly: false, secure: false, and sourceScheme: 'NonSecure'. Treat that as a guide example, not a default for production authentication cookies. In particular, insecure settings may be inappropriate for a real site or a test intended to model secure cookies.

Troubleshooting cookie setup

  • The cookie is not sent where expected: Check that the supplied url, domain, and path match the requests you are testing. A cookie scoped to localhost will not serve as a general cookie for another host.
  • The cookie disappears between sessions: If you omit expires, Puppeteer sets a session cookie. Supply an appropriate expiry only if the test needs persistence.
  • Tests see each other’s cookie state: Put each isolated scenario in its own BrowserContext and set cookies on that context.
  • A browser rejects or interprets an option differently: Verify that the option is supported by the browser in use. Puppeteer documents priority and sourceScheme as Chrome-only, and partition-key interpretation differs between Chrome and Firefox.
  • Older sample code uses page.setCookie(): Replace it with browser.setCookie() or context.setCookie(), consistent with the current API guidance.

Or skip the browser setup

If your goal is to capture a page rather than manage a Puppeteer test’s cookie state, ScreenshotNeo can return a screenshot or PDF with one GET request. Its API accepts the target URL and an access key; the full parameter documentation is at ScreenshotNeo docs.

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 banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never 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 1,000 free screenshots a month, with no card required.

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.

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.

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.