new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

web storage & cookies

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Storage state interchange between APIRequestContext and BrowserContext

Storage state from an authenticated APIRequestContext obtained via storage_state() can be passed to browser.new_context(storage_state=state) to create a BrowserContext with the same authentication cookies. This allows logging in via API and then using the authenticated session in browser tests.

Page.localStorage property type and usage

Page.localStorage property is of type WebStorage. It provides access to the page's localStorage for the current origin. Available since v1.61.

Page.sessionStorage property type and usage

Page.sessionStorage property is of type WebStorage. It provides access to the page's sessionStorage for the current origin. Available since v1.61.

storageState parameter structure - cookies and localStorage

For JavaScript and Python, storageState is a path or object containing cookies array and origins array. Cookies array items have: name (string), value (string), domain (string, required, prefix with dot for subdomains), path (string, required), expires (float, Unix time in seconds), httpOnly (boolean), secure (boolean), sameSite (SameSiteAttribute: 'Strict', 'Lax', or 'None'). Origins array items have: origin (string) and localStorage array with name (string) and value (string) properties. Populates context with given storage state.

APIRequestContext.storageState() method

APIRequestContext has a storageState() method that retrieves storage state (cookies and tokens) from an authenticated context as a String. This state can be reused to create new BrowserContext instances with the same authentication.

Storage state reuse between BrowserContext and APIRequestContext

Storage state is interchangeable between BrowserContext and APIRequestContext. You can retrieve storage state from an authenticated APIRequestContext using StorageStateAsync(), then create a new BrowserContext or APIRequestContext with that storage state via the StorageState option. This allows sharing authentication state between API and browser contexts.

Give your agent this brain