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
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
Functions
@spec clear(t()) :: :ok | {:error, Playwright.error()}
Removes all items from the storage.
Since Playwright 1.61.
@spec clear!(t()) :: :ok
Like clear/1, but returns the value and raises on error.
@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.
Like get_item/2, but returns the value and raises on error.
@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.
Like items/1, but returns the value and raises on error.
@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.
Like remove_item/2, but returns the value and raises on error.
@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.
Like set_item/3, but returns the value and raises on error.