Use Puppeteer’s BrowserContext cookie methods when you want to control cookies for a particular page and its context: call context.setCookie() before navigation, context.cookies() to read cookies, and a context deletion method to remove them. For the default context, browser.cookies(), browser.setCookie(), and browser.deleteCookie() are convenient alternatives. The right choice depends on which context owns the page and its storage.
Set a cookie before navigating
Create the page in the context whose cookie storage you want to use, set the cookie on that context, and then navigate. The following example uses the documented context-level API:
As an Amazon Associate I earn from qualifying purchases.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const context = await browser.createBrowserContext();
try {
const page = await context.newPage();
await context.setCookie({
name: 'session_hint',
value: 'example',
url: 'https://example.com',
secure: true,
httpOnly: true,
sameSite: 'Lax',
});
await page.goto('https://example.com');
const cookies = await context.cookies();
console.log(cookies);
await context.deleteMatchingCookies({ name: 'session_hint' });
} finally {
await context.close();
await browser.close();
}
This example illustrates the documented interface; it is not a claim that the code was executed. Check the types and documentation for your installed Puppeteer version before relying on optional fields or filter shapes. The official guide also shows the default-context pattern, using browser.cookies() to retrieve cookies and browser.setCookie() and browser.deleteCookie() to write and remove them. Puppeteer’s cookies guide includes an example with explicit domain, path, expiry, and security-related values.
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 →Choose the context that owns the page
A BrowserContext isolates browser storage, including cookies and localStorage. Pages opened in that context, including popups, belong to it. A cookie set in one context should not be assumed to be available to a page in another. Use the browser-level cookie methods for default-context work; use the corresponding BrowserContext methods when you need to work with a specific context’s state. See the BrowserContext API reference.
#1 Best Overall
- Default context: use
browser.cookies(),browser.setCookie(), orbrowser.deleteCookie()when the target page uses the default context. - Explicit context: create or select the context that owns the target page, then use its cookie methods. This is useful when you need to keep that page’s storage separate from another context’s.
Set the cookie’s scope and attributes deliberately
The values you provide determine where the cookie applies and how it behaves. The documented CookieData fields include name, value, domain, expires, httpOnly, partitionKey, path, priority, sameSite, secure, and sourceScheme. The CookieParam interface also documents url, which can affect default domain, path, and source scheme.
urlversusdomainandpath: these are not interchangeable. A URL can inform defaults; explicit domain and path values specify the intended scope. Use the host and path that should receive the cookie.secureandsameSite: set them to match the cookie’s intended security and cross-site behavior. Do not treat them as cosmetic fields.httpOnly: this is a cookie attribute. Do not assume every cookie can be read or changed through page JavaScript such asdocument.cookie.partitionKey: consider it when working with a partitioned cookie; omitting relevant partition information can mean you are not addressing the cookie you intend.- Chrome-supported fields: the interface descriptions mark
priorityandsourceSchemeas Chrome-supported. Verify that they fit your browser and installed Puppeteer version.
The interface references establish the available fields, not that every site or browser configuration will accept every cookie. A scope or attribute mismatch can prevent the cookie from being sent where you expect.
Rank #2
Read and verify cookies
Use the cookie-reading method on the same storage owner where you set the cookie: context.cookies() for a specific context or browser.cookies() for the default context. Inspect the returned cookie data to check its name and scope-related values. If it is absent, first verify that you are reading from the page’s actual context and that the cookie’s URL, domain, path, and partition information correspond to the intended site.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesDelete cookies with current APIs
For a context-scoped cleanup, context.deleteMatchingCookies() removes cookies matching the filters you provide. Use it when you want to target a cookie by a filter such as its name. The BrowserContext.deleteMatchingCookies() reference documents the method and its filters.
Rank #3
Puppeteer marks Page.deleteCookie() obsolete. Prefer deletion through Browser or BrowserContext, including matching-cookie deletion where appropriate, rather than building new code around the obsolete page method. See the Page.deleteCookie() reference for that deprecation guidance.
Troubleshoot cookies that do not appear or apply
- The page does not receive the cookie: confirm you set it on the same context that owns the page, and set it before navigation if the initial request needs it. Review the URL or explicit domain and path, plus secure and SameSite intent.
- Cookie reads return unexpected results: read from the owning context, not a different context or the default browser context by assumption.
- A cookie cannot be inspected with
document.cookie: Puppeteer’s cookie interfaces include thehttpOnlyattribute. Use Puppeteer’s browser or context cookie methods for browser storage rather than assuming page JavaScript can expose every cookie. - A field or deletion filter is rejected: check the exact types and signatures for the Puppeteer version installed in your project. The official reference results identify CookieData and BrowserContext at 25.12.0 and CookieParam at 25.11.0; those version labels do not establish that every project uses those versions.
- Deletion does not remove the intended cookie: ensure the deletion call targets the context that owns it and that the matching filter describes the cookie you want removed.
Or skip the browser setup
If your goal is a website screenshot rather than controlling browser storage in Puppeteer, ScreenshotNeo is a screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. For example, this cURL call saves a WebP screenshot of Stripe; see the ScreenshotNeo API documentation for request options and setup.
Quick Recap
Best Value
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 or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Product 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.




