Playwright’s Electron integration exposes a BrowserContext, but Electron cookies belong to an Electron Session. That boundary means ordinary Playwright cookie workflows should not be assumed to work with Electron. A logout can also come from cookie lifetime or scope, a different session or partition, or authentication state stored outside cookies—not necessarily a Playwright bug.
Why Playwright’s cookie API behaves differently with Electron
Playwright’s ElectronApplication API provides a context() method that returns a BrowserContext. But Playwright’s BrowserContext documentation says cookie retrieval returns null for contexts created outside a normal browser, explicitly including Electron. So receiving a context from Playwright does not mean every browser-context cookie operation applies to Electron.
As an Amazon Associate I earn from qualifying purchases.
Electron manages cookies through its own Session API. The relevant cookie store is the session used by the BrowserWindow making the request, which may be a custom partition rather than the default session. Electron documents cookie get, set, remove, and flush operations on Session.cookies; these APIs are available from the main process.
A 2022 report in Playwright issue #12096 describes context.cookies() failing with “Protocol error (Storage.getCookies): Browser context management is not supported.” That is evidence of a reported limitation at the time, not proof that every cookie operation fails in every current Playwright and Electron version.
#1 Best Overall
Find when the logout occurs
The timing narrows the diagnosis. Record the exact Playwright and Electron versions first: Playwright describes its Electron automation as experimental, and both products’ APIs evolve. Then identify the first point at which the app appears signed out.
- During the same run: Check whether the app navigated, opened a new window, or switched to a BrowserWindow using a different session or partition.
- After test teardown: Check whether the test closed the app or its session, or whether the test relied on state that was not saved and restored.
- Only after a full app restart: Check whether the cookie was a session cookie, whether it was written to disk, and whether the relaunch uses the same session and partition.
Inspect cookies through the Electron Session
- Identify the session: Find the Electron
Sessionused by the BrowserWindow involved in the request. Do not inspect a default session if the window uses a custom partition. - Read or change cookies there: Use that session’s
cookiesAPI from the main process. When setting a cookie, await thecookies.set()promise. - Check scope and acceptance conditions: Verify the cookie’s URL or domain and path, expiration, and
secureandSameSiteattributes against the request that needs it. - Check persistence: Electron treats a cookie set without
expirationDateas a session cookie, which is not retained between sessions. Cookie writes may also wait for periodic disk updates; useflushStore()when unwritten data must be written immediately.
Check whether login state lives outside cookies
A cookie check alone may not explain the app’s authentication state. Playwright’s authentication guide identifies cookies, localStorage, IndexedDB, and passkeys as possible authentication state. The app may use one of these, or combine several.
Rank #2
- localStorage or IndexedDB: Inspect the storage the app actually uses; a cookie-only check cannot establish whether that state is present.
- sessionStorage: Playwright’s documented storage-state workflow does not automatically persist it. A test that depends on sessionStorage may need explicit application-level save and restore logic.
- Passkeys or WebAuthn: Cookie handling alone does not capture these credentials.
Use storageState for the state it supports
Playwright’s storageState workflow is for documented browser-context authentication workflows, not a drop-in serialization method for Electron’s Session cookie store. Playwright documents storage snapshots that include cookies and localStorage, with options for additional supported state such as IndexedDB in current versions. For Electron cookies, use the Electron Session associated with the relevant window; determine separately how the app’s other authentication state is saved or recreated.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Quick Recap
Rank #4
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.




