Skip to content

Add Set Storage State keyword and indexedDB=/credentials= arguments on Save Storage State #5117

Description

@Snooz82

Use case

Save Storage State already lets users snapshot an authenticated session (cookies + local storage) and reuse it via New Context storageState=.... Two pieces of the storage-state story are still missing:

  1. Restoring state into an already-running context. Today the only way to switch the logged-in user is to close the current context and create a new one with storageState= — which throws away all open pages, their navigation state, registered promises, console logs, etc. Playwright 1.59 added browserContext.setStorageState(), which clears and re-seeds the current context's storage in place. A Set Storage State keyword lets a suite log in as user A, act, then swap to user B mid-context without rebuilding anything.

  2. Saving the full modern auth state. Many apps (notably Firebase/Firestore-based ones) keep their auth tokens in IndexedDB, and passkey/WebAuthn credentials live in the credential store — neither is captured by the current Save Storage State, so the record-once-log-in-forever pattern silently fails for those apps. Playwright's storageState() accepts indexedDB and credentials flags to include them; there is no workaround today.

Both halves belong to one story: what Save Storage State can capture, Set Storage State (and New Context storageState=) can restore.

Proposed keyword / arguments

New keyword:

  • Set Storage State path — clears the current context's cookies/storage and re-seeds them from a state file previously produced by Save Storage State.

Extended keyword (new named-only arguments, defaults preserve current output):

  • Save Storage State *, indexedDB=False credentials=False
*** Test Cases ***
Reuse Firebase Login Across Users
    New Context
    New Page    ${LOGIN_URL}
    Log In As    userA
    ${state_a}=    Save Storage State    indexedDB=True
    Log Out
    Log In As    userB
    ${state_b}=    Save Storage State    indexedDB=True

    # Later, switch users without recreating the context
    Set Storage State    ${state_a}
    Reload
    Get Text    id=current-user    ==    userA
    Set Storage State    ${state_b}
    Reload
    Get Text    id=current-user    ==    userB

Playwright API

Implementation notes

  • protobuf/playwright.proto: new RPC for SetStorageState (path in request); extend the existing SaveStorageState request with the two boolean flags.
  • node/playwright-wrapper: call context.setStorageState({path}); pass indexedDB/credentials through to context.storageState().
  • Browser/keywords/playwright_state.py: new set_storage_state keyword; two new named-only args on save_storage_state (which today takes no arguments and writes to ${OUTPUTDIR}/browser/state).
  • Docs + atest: round-trip test — save with indexedDB=True, mutate storage, Set Storage State, assert restored values.

Backwards compatibility

Fully additive: Set Storage State is a new keyword, and the new Save Storage State arguments are named-only booleans defaulting to False, matching Playwright's defaults and the keyword's current output exactly.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions