---
id: api/commands/clearalllocalstorage
title: cy.clearAllLocalStorage()
description: Clear all localStorage data in Cypress.
section: api
source_path: docs/api/commands/clearalllocalstorage.mdx
version: f60251bf707b0077a9535579c9f90d615440cc35
updated_at: '2026-10-16T10:56:58.670Z'
---
# clearAllLocalStorage

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

Cypress automatically clears all local storage _before_ each test to prevent state from being shared across tests when [test isolation](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Test-Isolation) is enabled. You shouldn't need to use this command unless you're using it to clear localStorage inside a single test or test isolation is disabled.

## Syntax

```
cy.clearAllLocalStorage()
cy.clearAllLocalStorage(options)
```

### Usage

**Correct Usage**

```
cy.clearAllLocalStorage()
```

### Arguments

**options _(Object)_**

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

| Option | Default | Description |
| --- | --- | --- |
| `log` | `true` | Displays the command in the [Command Log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |

### Yields

*   `cy.clearAllLocalStorage()` yields `null`.

## Examples

### No Args

#### Clear local storage for every origin[

End-to-End Only

](/llm/markdown/app/core-concepts/testing-types.md#What-is-E2E-Testing)

`cy.clearAllLocalStorage()` clears `localStorage` on every origin the test has loaded a page from, including origins visited inside [`cy.origin()`](/llm/markdown/api/commands/origin.md).

```
cy.visit('https://example.cypress.io')
cy.window().then((win) => win.localStorage.setItem('theme', 'dark'))
cy.origin('https://www.cypress-dx.com', () => {
  cy.visit('/')
  cy.window().then((win) => win.localStorage.setItem('theme', 'light'))
})
cy.getAllLocalStorage().should('not.be.empty')
cy.clearAllLocalStorage()
cy.getAllLocalStorage().should('be.empty')
```

### Options

#### Clear local storage without logging to the Command Log

Pass `{ log: false }` to keep `cy.clearAllLocalStorage()` out of the [Command Log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log), which is useful when it runs in a hook before every test and would otherwise repeat in every test's log.

```
cy.clearAllLocalStorage({ log: false })
```

### Common workflows

#### Reset local storage between tests with test isolation off[

End-to-End Only

](/llm/markdown/app/core-concepts/testing-types.md#What-is-E2E-Testing)

When [test isolation](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Test-Isolation) is off, `localStorage` carries over from one test to the next. Clear it in a `beforeEach()` hook so each test starts from the same state. Pair it with [`cy.clearAllCookies()`](/llm/markdown/api/commands/clearallcookies.md) and [`cy.clearAllSessionStorage()`](/llm/markdown/api/commands/clearallsessionstorage.md) for a full reset.

```
describe('checkout', { testIsolation: false }, () => {
  beforeEach(() => {
    cy.clearAllCookies()
    cy.clearAllLocalStorage()
    cy.clearAllSessionStorage()
  })
})
```

#### Forget a remembered user on a sign-in origin[

End-to-End Only

](/llm/markdown/app/core-concepts/testing-types.md#What-is-E2E-Testing)

When your app signs users in on a separate origin, that sign-in page can remember the user in its own `localStorage`. [`cy.clearLocalStorage()`](/llm/markdown/api/commands/clearlocalstorage.md) reaches only the current origin, so use `cy.clearAllLocalStorage()` to forget the user on every origin and test the signed-out experience.

```
cy.visit('/')
cy.origin('https://www.cypress-dx.com', () => {
  cy.visit('/login')
  cy.get('[data-cy="email"]').type('user@example.com')
  cy.get('[data-cy="remember-me"]').check()
  cy.get('[data-cy="login"]').click()
})

cy.clearAllLocalStorage()

cy.origin('https://www.cypress-dx.com', () => {
  cy.visit('/login')
  cy.get('[data-cy="email"]').should('have.value', '')
})
```

#### Choose between cy.clearLocalStorage() and cy.clearAllLocalStorage()

[`cy.clearLocalStorage()`](/llm/markdown/api/commands/clearlocalstorage.md) clears the current origin and can target specific keys. `cy.clearAllLocalStorage()` clears every key on every tracked origin.

```
// Clear one key on the current origin
cy.clearLocalStorage('authToken')

// Clear every key on every tracked origin
cy.clearAllLocalStorage()
```

## Notes

### Origins cleared by cy.clearAllLocalStorage()

Cypress tracks every origin that serves an HTML page, and `cy.clearAllLocalStorage()` clears `localStorage` for each of them. When [test isolation](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Test-Isolation) is enabled, Cypress resets that list at the start of each test. When it's off, the list carries over between the tests in a spec file, so the command also clears origins that earlier tests in the spec loaded.

### HTTP origins in an HTTPS test

When your app runs on HTTPS, `cy.clearAllLocalStorage()` clears only the HTTPS origins and leaves `localStorage` on any HTTP origins in place. Browsers block an HTTPS page from reaching an HTTP origin's storage. If every origin your test visits uses the same protocol, this doesn't affect you.

## Rules

### Requirements

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

### Assertions

*   `cy.clearAllLocalStorage()` yields `null`, so there's nothing to assert on. To confirm local storage is cleared, assert on [`cy.getAllLocalStorage()`](/llm/markdown/api/commands/getalllocalstorage.md) afterward, for example `cy.getAllLocalStorage().should('be.empty')`.

### Timeouts

*   `cy.clearAllLocalStorage()` cannot time out. When an origin doesn't respond within 2 seconds, the command logs a warning and continues.

## History

| Version | Changes |
| --- | --- |
| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | `cy.clearAllLocalStorage()` command added |

## See also

*   [`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.getAllLocalStorage()`](/llm/markdown/api/commands/getalllocalstorage.md)
*   [`cy.getAllSessionStorage()`](/llm/markdown/api/commands/getallsessionstorage.md)
