---
id: api/commands/getalllocalstorage
title: cy.getAllLocalStorage()
description: >-
  Get localStorage data for all origins with which the test has interacted in
  Cypress.
section: api
source_path: docs/api/commands/getalllocalstorage.mdx
version: efcbe8c28d49ff52285a47072f279cb65f20c0fc
updated_at: '2026-09-09T13:41:20.773Z'
---
# getAllLocalStorage

Get [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) data for all origins with which the test has interacted.

## Syntax

```
cy.getAllLocalStorage()
cy.getAllLocalStorage(options)
```

### Usage

**Correct Usage**

```
cy.getAllLocalStorage()
```

### Arguments

**options _(Object)_**

Pass in an options object to change the default behavior of `cy.getAllLocalStorage()`.

| Option | Default | Description |
| --- | --- | --- |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.getAllLocalStorage()` to resolve before [timing out](#Timeouts) |

### Yields

`cy.getAllLocalStorage()` yields an object where the keys are origins and the values are key-value pairs of `localStorage` data.

For example, if `key1` is set to `value1` on `https://example.cypress.io` and `key2` is set to `value2` on `https://www.cypress-dx.com`, `cy.getAllLocalStorage()` will yield:

```
{
  'https://example.cypress.io': {
    key1: 'value1',
  },
  'https://www.cypress-dx.com': {
    key2: 'value2',
  },
}
```

`cy.getAllLocalStorage()` is a query, and it is _safe_ to chain further commands. It will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed, or until it times out, re-reading `localStorage` from all origins on each retry so the yielded object stays up to date.

Because `cy.getAllLocalStorage()` is a query, it re-reads `localStorage` on every retry, and assertions you chain with [`.should()`](/llm/markdown/api/commands/should.md) drive those retries until they pass or the command times out. A [`.then()`](/llm/markdown/api/commands/then.md) callback, by contrast, runs only once after the command settles and is not retried — so prefer chaining [`.should()`](/llm/markdown/api/commands/should.md) assertions over asserting inside `.then()` when you need Cypress to wait for storage to be populated.

#### When no `localStorage` data is present:

On each read, `cy.getAllLocalStorage()` yields the current object of origins to `localStorage` data, or an empty object if none exists yet. The yielded object is the subject your chained assertions run against. If an assertion fails, because the object is empty, or because its contents don't match yet, the query re-reads `localStorage` and re-runs the assertion, looping until it passes or the command times out.

## Examples

### Get all localStorage

```
cy.visit('https://example.cypress.io', {
  onBeforeLoad(win) {
    win.localStorage.setItem('key', 'value')
  },
})

cy.getAllLocalStorage().then((result) => {
  expect(result).to.deep.equal({
    'https://example.cypress.io': {
      key: 'value',
    },
  })
})
```

## Rules

### Requirements

*   `cy.getAllLocalStorage()` requires being chained off of `cy`.

### Assertions

*   `cy.getAllLocalStorage()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.

### Timeouts

*   `cy.getAllLocalStorage()` can time out waiting for assertions you've added to pass.

## History

| Version | Changes |
| --- | --- |
| [16.0.0](/llm/markdown/app/references/changelog.md#16-0-0) | `cy.getAllLocalStorage()` is now a query and retries assertions until they pass or time out. |

## See also

*   [`cy.clearAllLocalStorage()`](/llm/markdown/api/commands/clearalllocalstorage.md)
*   [`cy.clearAllSessionStorage()`](/llm/markdown/api/commands/clearallsessionstorage.md)
*   [`cy.clearCookies()`](/llm/markdown/api/commands/clearcookies.md)
*   [`cy.clearLocalStorage()`](/llm/markdown/api/commands/clearlocalstorage.md)
*   [`cy.getAllSessionStorage()`](/llm/markdown/api/commands/getallsessionstorage.md)
