Skip to content

[Feature]: Save Session Storage when extracting the browser Storage State #38682

@AbdelrahmanFahd

Description

@AbdelrahmanFahd

🚀 Feature Request

Extend the storageState() method to capture and restore sessionStorage alongside cookies and localStorage.
This would allow us to save and reload the complete browser storage state, including session-specific data.

Example

`// Save storage state including sessionStorage
await page.context().storageState({ path: 'auth-state.json', sessionStorage: true })

// Restore all storage types from saved state
const browser = await chromium.launch();
const context = await browser.newContext({
storageState: 'auth-state.json' // Automatically restores cookies, localStorage, and sessionStorage
});`

Motivation

Many modern web applications store critical authentication tokens, temporary user preferences, or application state in sessionStorage rather than localStorage. Currently, Playwright's storageState() doesn't capture sessionStorage, forcing us to:

  • Manually extract and restore sessionStorage using page.evaluate()
  • Write custom helper functions to work around this limitation

Adding sessionStorage support would:

  • Improve test reliability: Preserve complete browser state between test runs
  • Reduce test setup time: Eliminate redundant authentication/initialization steps
  • Enhance API consistency: Make storageState() comprehensive for all Web Storage APIs
  • Simplify test code: Remove boilerplate for manual sessionStorage management

This feature would be particularly valuable for applications using OAuth flows, SPAs with session-based state management, or any system relying on sessionStorage for functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions