Use browser.cookies() to read cookies and browser.setCookie(...) to set them in Puppeteer’s default browser context. If your pages belong to an isolated context, use that context’s cookie methods instead. The older page.cookies() and page.setCookie() methods are deprecated; use the browser or context APIs for new code.
Read and set cookies in Puppeteer’s default context
This example sets a cookie before navigating, reads cookies from the default context, and closes the browser even if an operation fails. Replace the example cookie and origin with values appropriate to your test.
As an Amazon Associate I earn from qualifying purchases.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await browser.setCookie({
name: 'session',
value: 'example-value',
domain: 'localhost',
path: '/',
httpOnly: false,
secure: false,
});
console.log(await browser.cookies());
await page.goto('http://localhost');
} finally {
await browser.close();
}
Puppeteer’s cookie guide demonstrates setting and reading cookies with browser.setCookie() and browser.cookies(). The example above adapts that API shape; it is not a guarantee that the sample cookie will authenticate against any particular application.
Free tools Windows power users keep installed
One-click scans. No signup required.
What the cookie fields mean
The CookieData reference requires name, value, and domain. It also documents optional fields including:
#1 Best Overall
path: the cookie path.expires: an optional expiry; when omitted, the interface describes the cookie as a session cookie.httpOnlyandsecure: boolean cookie attributes.sameSite: the cookie’s documented SameSite setting.partitionKey: partition information, whose description differs for Chrome and Firefox.
Use attributes that match the application and browser under test. The API reference includes browser-specific support notes, so do not assume every optional field behaves identically in every browser.
Choose the right cookie scope
Cookies belong to a browser context. Puppeteer describes contexts as isolating storage, including cookies and local storage. The browser-level cookie methods are shortcuts for the default context; for a separate test context, use that context for setup and inspection.
Rank #2
| API | Scope | Use it when |
|---|---|---|
browser.cookies() / browser.setCookie(...) |
The default BrowserContext. |
Your pages use the default context and you want the browser-level shortcut. |
context.cookies() / context.setCookie(...) |
The particular context object. | A test uses an isolated context and its cookie state should remain separate. |
The Browser.cookies() reference specifies the default context. The Browser.setCookie() reference and BrowserContext.setCookie() reference document the corresponding set methods.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallUse a specific context
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const context = await browser.createBrowserContext();
const page = await context.newPage();
await context.setCookie({
name: 'session',
value: 'example-value',
domain: 'localhost',
path: '/',
httpOnly: false,
secure: false,
});
console.log(await context.cookies());
await page.goto('http://localhost');
} finally {
await browser.close();
}
Keep setup, reads, and cleanup on the same context. Calling browser.cookies() while the test’s page is in another context inspects the default context, not that isolated store. See Puppeteer’s API reference for the current context API.
Set a cookie before navigation
- Launch Puppeteer and create the page or context that will own the test’s state.
- Call that owner’s
setCookie()with the cookie data, including a domain that matches the site you intend to visit. - Optionally call the same owner’s
cookies()method to inspect the stored cookies. - Navigate to the site after setting the cookie.
- Close the browser or otherwise clean up the test context when finished.
A cookie for localhost is not a drop-in cookie for another host. Adjust the domain and attributes to the test origin; the interface reference lists the supported data fields.
Why page.setCookie() is deprecated
Puppeteer marks Page.setCookie() obsolete and directs users to Browser.setCookie() or BrowserContext.setCookie(). Its page cookie reader is likewise deprecated in favor of the browser or context reader. The older Page.setCookie() and Page.cookies() references are useful for migration context, not as the pattern for new code.
Rank #4
The CookieParam reference documents a url property for the page-level API and notes its effect on defaults such as domain, path, and source scheme. Treat that as legacy API context rather than a reason to continue using the deprecated Page methods.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Use cookie storage in automated tests
Puppeteer’s guide describes storage manipulation as useful for storing and restoring cookies in tests: “This is useful if you need to store and restore specific cookies for your tests.” A practical test can seed a known cookie state before visiting a page, then read back the relevant state while staying within the same context. Keep test state isolated when tests should not share cookies.
Best Value
- Used Book in Good Condition
Troubleshooting cookie setup
- The page does not appear to use the cookie: Confirm the cookie domain matches the page’s host, that you set it before navigation when that is the intended sequence, and that you used the same context for setting it and opening the page.
- The read returns unexpected cookies: Check whether the page is in an isolated context while you are reading from
browser.cookies(), which covers the default context. Read from the page’s owning context instead. - A cookie field is rejected or behaves differently: Compare the supplied fields with the
CookieDatadefinition and its browser-specific support notes. The API documentation does not establish identical support across browsers. - Existing code uses Page cookie methods: Replace Page-level reads and writes with the matching default-browser or specific-context methods, according to where the page’s storage lives.
Or skip the browser setup
ScreenshotNeo is a website screenshot API, not a replacement for Puppeteer’s cookie-storage APIs. If the job is to capture a page rather than manage browser cookies yourself, one GET request can return an image or PDF. API details are in the ScreenshotNeo documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie and consent banners are accepted and removed before capture; newsletter popups and chat widgets are removed too, and each step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include
X-Page-VerdictandX-Billedheaders. - An MCP server offers
take_screenshot,get_page_info, andcapture_pdftools for AI agents and MCP clients. - The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.
Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Frequently Asked Questions
Can I use Puppeteer cookie methods to save and restore test state?
Yes. Puppeteer’s cookie guide identifies storing and restoring specific cookies for tests as a use case for its storage methods.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Does a browser-level cookie read inspect every context?
No. browser.cookies() is documented for the default BrowserContext; read from the specific context when your page uses an isolated one.
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.

