Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteTo 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.
For storage isolated to a particular browser context, use that context directly:
#1 Best Overall
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.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.
Rank #3
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.
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
priorityandsourceSchemeas Chrome-only, and partition-key interpretation differs between Chrome and Firefox. - Older sample code uses
page.setCookie(): Replace it withbrowser.setCookie()orcontext.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.
Quick Recap
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.




