# `Playwright.WebStorage`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.3/lib/playwright/api/web_storage.ex#L7)

WebStorage exposes the page's `localStorage` or `sessionStorage` for the current origin via a
[browser-consistent](https://developer.mozilla.org/en-US/docs/Web/API/Storage) API.

Instances are accessed through `Playwright.Page.local_storage/1` and `Playwright.Page.session_storage/1`.

```elixir
Page.goto!(page, "https://example.com")
Page.local_storage(page) |> WebStorage.set_item!("token", "abc")
token = Page.local_storage(page) |> WebStorage.get_item!("token")
all = Page.local_storage(page) |> WebStorage.items!()
Page.local_storage(page) |> WebStorage.remove_item!("token")
Page.local_storage(page) |> WebStorage.clear!()
```

*Since Playwright 1.61.*

The examples alias the modules they use (`alias Playwright.{Locator, Page}`).

# `t`

```elixir
@type t() :: %Playwright.WebStorage{_kind: term(), _page: term()}
```

A `WebStorage` handle. Compare handles with `==`, their fields are internal.

# `clear`

```elixir
@spec clear(t()) :: :ok | {:error, Playwright.error()}
```

Removes all items from the storage.

*Since Playwright 1.61.*

# `clear!`

```elixir
@spec clear!(t()) :: :ok
```

Like `clear/1`, but returns the value and raises on error.

# `get_item`

```elixir
@spec get_item(t(), String.t()) ::
  {:ok, nil | String.t()} | {:error, Playwright.error()}
```

Returns the value for the given `name` if present.

*Since Playwright 1.61.*

## Arguments

* `name` - Name of the item to retrieve.

# `get_item!`

```elixir
@spec get_item!(t(), String.t()) :: nil | String.t()
```

Like `get_item/2`, but returns the value and raises on error.

# `items`

```elixir
@spec items(t()) ::
  {:ok, [%{name: String.t(), value: String.t()}]} | {:error, Playwright.error()}
```

Returns all items in the storage as name/value pairs.

*Since Playwright 1.61.*

# `items!`

```elixir
@spec items!(t()) :: [%{name: String.t(), value: String.t()}]
```

Like `items/1`, but returns the value and raises on error.

# `remove_item`

```elixir
@spec remove_item(t(), String.t()) :: :ok | {:error, Playwright.error()}
```

Removes the item with the given `name`. No-op if the item is absent.

*Since Playwright 1.61.*

## Arguments

* `name` - Name of the item to remove.

# `remove_item!`

```elixir
@spec remove_item!(t(), String.t()) :: :ok
```

Like `remove_item/2`, but returns the value and raises on error.

# `set_item`

```elixir
@spec set_item(t(), String.t(), String.t()) :: :ok | {:error, Playwright.error()}
```

Sets the value for the given `name`. Overwrites any existing value for that name.

*Since Playwright 1.61.*

## Arguments

* `name` - Name of the item to set.
* `value` - New value for the item.

# `set_item!`

```elixir
@spec set_item!(t(), String.t(), String.t()) :: :ok
```

Like `set_item/3`, but returns the value and raises on error.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
