Skip to main content

Storage & Authentication

Manage cookies, localStorage, sessionStorage, and save/restore full browser state for authentication persistence. Requires the storage capability.

{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--caps=storage"]
}
}
}

Storage state

Save and restore the full browser state (cookies + local storage) in a single file. This is the primary way to persist authentication across sessions.

browser_storage_state

Save the current state to a JSON file.

ParameterTypeRequiredDescription
filenamestringnoFile to save to. Relative names resolve against the workspace root. Defaults to storage-state-{timestamp}.json in the output directory
→ browser_storage_state { filename: "auth-state.json" }
- [Storage state](auth-state.json)

browser_set_storage_state

Restore a previously saved state. Existing cookies and local storage are cleared first.

ParameterTypeRequiredDescription
filenamestringyesPath to the storage state file. Relative names resolve against the workspace root
→ browser_set_storage_state { filename: "auth-state.json" }
Storage state restored from auth-state.json

→ browser_navigate { url: "https://app.example.com/dashboard" }
// Already logged in
- heading "Dashboard" [level=1] [ref=e2]

Workflow: save login, skip it next time

// Login once
→ browser_navigate { url: "https://app.example.com/login" }
→ browser_type { target: "e3", text: "alice@example.com" }
→ browser_type { target: "e5", text: "s3cret!" }
→ browser_click { target: "e7" }

- heading "Dashboard" [level=1] [ref=e2]

// Save
→ browser_storage_state { filename: "auth-state.json" }

// Next session: restore instead of logging in
→ browser_set_storage_state { filename: "auth-state.json" }
→ browser_navigate { url: "https://app.example.com/dashboard" }

Or load state automatically on server startup:

["@playwright/mcp@latest", "--caps=storage", "--isolated", "--storage-state=./auth-state.json"]

Cookies

ParameterTypeRequiredDescription
domainstringnoFilter cookies by domain
pathstringnoFilter cookies by path
→ browser_cookie_list

session_id=abc123 (domain: .example.com, path: /)
theme=dark (domain: .example.com, path: /)
ParameterTypeRequiredDescription
namestringyesCookie name to get
→ browser_cookie_get { name: "session_id" }

session_id=abc123 (domain: .example.com, path: /, httpOnly: true, secure: true, sameSite: Lax)

Domain defaults to the current page's hostname and path defaults to /.

ParameterTypeRequiredDescription
namestringyesCookie name
valuestringyesCookie value
domainstringnoCookie domain
pathstringnoCookie path
expiresnumbernoExpiration as a Unix timestamp
httpOnlybooleannoWhether the cookie is HTTP only
securebooleannoWhether the cookie is secure
sameSitestringnoStrict, Lax, or None

Delete a specific cookie by name, or clear all cookies.

Workflow: test logout by clearing cookies

→ browser_cookie_clear
→ browser_navigate { url: "https://app.example.com/dashboard" }

- heading "Sign in" [level=1] [ref=e2]
- textbox "Email" [ref=e3]

localStorage

Manage localStorage key-value pairs for the current origin.

ToolParameters
browser_localstorage_list(none)
browser_localstorage_getkey (string)
browser_localstorage_setkey (string), value (string)
browser_localstorage_deletekey (string)
browser_localstorage_clear(none)
→ browser_localstorage_list

user_preferences={"theme":"dark","lang":"en"}
onboarding_done=true

→ browser_localstorage_set { key: "onboarding_done", value: "false" }
→ browser_navigate { url: "https://app.example.com" }

// Onboarding wizard appears
- heading "Welcome! Let's get started" [level=1] [ref=e2]

sessionStorage

Same interface as localStorage but session-scoped — data is cleared when the tab closes.

ToolParameters
browser_sessionstorage_list(none)
browser_sessionstorage_getkey (string)
browser_sessionstorage_setkey (string), value (string)
browser_sessionstorage_deletekey (string)
browser_sessionstorage_clear(none)