Playwright.WebStorage (Playwright v1.65.0-rc.3)

Copy Markdown View Source

WebStorage exposes the page's localStorage or sessionStorage for the current origin via a browser-consistent API.

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

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}).

Summary

Types

t()

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

Functions

Removes all items from the storage.

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

Returns the value for the given name if present.

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

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

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

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

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

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

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

Types

t()

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

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

Functions

clear(web_storage)

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

Removes all items from the storage.

Since Playwright 1.61.

clear!(web_storage)

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

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

get_item(web_storage, name)

@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!(web_storage, name)

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

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

items(web_storage)

@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!(web_storage)

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

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

remove_item(web_storage, name)

@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!(web_storage, name)

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

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

set_item(web_storage, name, value)

@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!(web_storage, name, value)

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

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