Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Set cookies on the BrowserContext that owns the page, then navigate to the site. In current Puppeteer documentation, Page.setCookie() is obsolete; use page.browserContext().setCookie() for a particular page’s context, or browser.setCookie() when you mean the default context.
Set a cookie before navigating
This example sets a cookie in the context associated with page, then opens the matching site. It uses the documented browser-level cookie data fields; adapt the domain, value, and flags to the site and session you are configuring.
As an Amazon Associate I earn from qualifying purchases.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
const context = page.browserContext();
await context.setCookie({
name: 'session',
value: 'example-value',
domain: 'example.com',
path: '/',
httpOnly: true,
secure: true,
sameSite: 'Lax',
});
await page.goto('https://example.com');
} finally {
await browser.close();
}
})();
The cookie is configured before page.goto(), so it is available to requests made in that context for the matching site scope. The example is documentation-based; the correct cookie scope and flags depend on the target application.
Use the default context when that is your target
If the page uses Puppeteer’s default browser context, the browser-level method is a shortcut:
#1 Best Overall
await browser.setCookie({
name: 'session',
value: 'example-value',
domain: 'example.com',
path: '/',
});
This calls the default context’s cookie-setting method. Do not use this shortcut when the page you intend to configure belongs to a separately created context.
Choose the cookie scope and fields
The current browser-level CookieData interface requires name and value; it also documents domain. Other documented fields let you set expiration, security behavior, and scope. Match these values to the site rather than copying a sample blindly.
nameandvalue: the cookie’s key and contents.domainandpath: where the cookie applies. Use a domain and path that match the intended site scope.httpOnly: use when the application requires a cookie that client-side scripts cannot read.secure: set totruefor a cookie intended for secure transport, such as over HTTPS.sameSite: select a policy that fits the application’s cross-site request requirements; the example uses'Lax'.expires: an expiration date represented as a number. If omitted, the cookie is a session cookie.url: can affect default domain, path, and source-scheme values.- Other documented optional properties include partitioning, priority, and source scheme. Check the interface and browser support for your installed Puppeteer version before relying on browser-specific fields.
Use the context that owns the page
Browser contexts isolate storage, including cookies and local storage. A newly created context does not share cookies or cache with other contexts. Setting a cookie in one context therefore does not configure a page in another.
Recommended Free Tools
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
For a page-specific setup, obtain its context with page.browserContext() and call setCookie() there. If you create contexts yourself, keep and use the context associated with the page you intend to configure. Use browser.setCookie() only when the default context is the intended one.
Replace obsolete page.setCookie() calls
The current Puppeteer Page API marks page.setCookie() obsolete and directs users to Browser.setCookie() or BrowserContext.setCookie(). For code tied to a particular page, migrate to its context:
// Old pattern: page.setCookie(cookieData)
// Current pattern:
await page.browserContext().setCookie(cookieData);
If the old code deliberately used the default browser context, use await browser.setCookie(cookieData) instead. The key is to preserve the intended context, not merely to change the method name.
Rank #3
Inspect cookies in the default context
The current Browser API documents browser.cookies() as returning cookies in the default BrowserContext:
Free tools Windows power users keep installed
One-click scans. No signup required.
const cookies = await browser.cookies();
console.log(cookies);
This is useful for checking default-context state. It does not inspect cookies stored in every separately created context.
Or skip the browser setup
If your goal is to capture a page screenshot rather than configure cookies for an automation session, ScreenshotNeo offers a one-request screenshot API. It is not a replacement for Puppeteer cookie setup; it is an option when you need the screenshot itself.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
For example, this cURL request saves a screenshot of Stripe’s site. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot cookie setup
The site does not receive the cookie
- Confirm you set it on the context that owns the target page. Contexts do not share cookie storage.
- Check that
domainandpathmatch the URL you are visiting. - If the cookie is marked
secure: true, use the secure scheme expected by the application. - Set the cookie before navigation when the initial request needs to include it.
The cookie is missing when you inspect it
Check which context you are inspecting. browser.cookies() reports cookies in the default context, so it will not show cookies held only by a separate context. Inspect or configure the context associated with the page instead.
Best Value
page.setCookie() is flagged as obsolete
Move the call to page.browserContext().setCookie() for the page’s context, or to browser.setCookie() if the default context is intended. Preserve the original cookie data and verify the context choice.
A cookie option is rejected or has no effect
Confirm the field name, value type, and support in the Puppeteer version and browser you are running. The documented interface includes browser-specific optional fields such as priority and source scheme; do not assume every installed version supports every field.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesPerformance and reliability considerations
Set cookies in the correct context before the navigation that depends on them, and avoid creating a separate context unless you need isolated storage. Context isolation is useful for keeping sessions separate, but it also means cookies and cache are not shared. Cookie acceptance alone does not guarantee that a site will authenticate the session: the value, scope, expiry, and any application-side requirements must also be valid.
The examples show API usage rather than a live-browser validation. For project-specific behavior, check the installed Puppeteer version’s API reference and the target application’s cookie requirements.
Quick Recap
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.




