Skip to main content
Read and write browser cookies to manage authentication, sessions, and user preferences.

Methods

page.cookies()

Gets all cookies visible to a given URL.
Parameters:
  • url: URL to get cookies for (cookies are domain-scoped)
Returns: Promise<Cookie[]> - Array of cookie objects Example:

page.setCookie()

Sets one or more cookies.
Parameters:
  • cookies: One or more cookie objects to set
Returns: Promise<void> Example:

Complete examples

Check authentication status

Transfer session between browsers

Inject authentication cookies

Save and restore session

Clear cookies

Manage user preferences

A/B testing with cookies

Best practices

Ensure the URL domain matches the cookie domain:
Use the secure flag for cookies on HTTPS sites:
Always check if cookies exist before accessing:

Authentication

Handle authentication flows

Navigation

Navigate with cookies set

JavaScript

Access cookies via JavaScript

Page overview

Back to Page API overview