If you use Playwright CLI for browser automation, storage state is one of the most useful features. Its job is simple: save the current login session and local browser state so you can reuse them later instead of logging in every time.
01 Save the current storage state
The most common workflow is to log in once, then export the current state to a file.
|
|
This command saves the current browser context state to auth.json. If you want to reuse a login session later, this is usually the first step.
02 Load an existing storage state
Once you already have a state file, you can load it directly at startup.
|
|
It launches the browser context with the state stored in auth.json. The usual purpose is to skip repeated login and jump straight into a signed-in environment.
03 View current cookies
If you only want to check which cookies exist in the current session, you can inspect them directly.
|
|
This command lists the cookies in the current context. It is useful when checking whether the login state exists or whether cookies were written successfully.
04 Set cookies
If you already have cookie data, you can inject it directly as well.
|
|
This is useful for auth debugging, reproducing a specific session, or injecting cookie conditions before a script runs.
05 Read localStorage
Some sites store login-related or frontend state not only in cookies, but also in localStorage.
|
|
This command shows the localStorage content of the current page. It is especially useful when a page looks logged in but still behaves incorrectly.
06 Write localStorage
If you need to simulate specific frontend state, you can set it directly.
|
|
It writes the given key and value into localStorage. Common uses include injecting a token, a preference, or a frontend flag.
07 Read sessionStorage
sessionStorage is useful for checking temporary state tied to the current session.
|
|
This command outputs the current page’s sessionStorage. If a page flow depends on one-time session data, this is a good place to inspect it.
08 Write sessionStorage
When needed, you can also set sessionStorage manually.
|
|
It is useful for reproducing page behavior that depends on temporary state, or for filling in fields required by an initialization step.
09 View IndexedDB
For heavier web apps, the most important local data may actually live in IndexedDB.
|
|
This command lets you inspect the current page’s IndexedDB data. It is worth checking first when you are dealing with complex SPAs, offline cache, or app-like local databases.
10 A practical workflow
If your goal is simply to reuse a login session reliably, the most practical flow is usually this:
- Open the site and complete login manually.
- Save the state with this command:
|
|
- Load it directly in later runs:
|
|
If the page still behaves incorrectly after loading, continue by checking:
playwright-cli cookiesplaywright-cli local-storageplaywright-cli session-storageplaywright-cli indexed-db
That sequence covers most cases where the restored state is incomplete.
11 What to watch out for
Three points matter most:
- A
storage statefile is sensitive data. It may contain login cookies or tokens, so do not commit it casually. - Restoring cookies alone may not be enough. Many modern sites also depend on
localStorage,sessionStorage, orIndexedDB. - State files do not stay valid forever. After cookie expiration, account changes, or environment changes, you usually need to generate them again.
12 Quick summary
If you only remember one sentence:
Playwright CLI storage state means saving the browser’s current state and reusing it in later tasks.
In practice, the most useful commands are these:
|
|
Save first, then load; if something still looks wrong, inspect cookies and the different local storage layers one by one. That is the most practical part of this reference.
References
- Playwright CLI storage-state reference: https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/storage-state.md
- Playwright CLI project page: https://github.com/microsoft/playwright-cli