Skip to main content

WebStorage

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

Instances are accessed through Page.LocalStorage and Page.SessionStorage.

await page.GotoAsync("https://example.com");
await page.LocalStorage.SetItemAsync("token", "abc");
var token = await page.LocalStorage.GetItemAsync("token");
var all = await page.LocalStorage.ItemsAsync();
await page.LocalStorage.RemoveItemAsync("token");
await page.LocalStorage.ClearAsync();

Methods

ClearAsync

Added in: v1.61 webStorage.ClearAsync

Removes all items from the storage.

Usage

await WebStorage.ClearAsync();

Returns


GetItemAsync

Added in: v1.61 webStorage.GetItemAsync

Returns the value for the given name if present.

Usage

await WebStorage.GetItemAsync(name);

Arguments

  • name string#

    Name of the item to retrieve.

Returns


ItemsAsync

Added in: v1.61 webStorage.ItemsAsync

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

Usage

await WebStorage.ItemsAsync();

Returns


RemoveItemAsync

Added in: v1.61 webStorage.RemoveItemAsync

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

Usage

await WebStorage.RemoveItemAsync(name);

Arguments

  • name string#

    Name of the item to remove.

Returns


SetItemAsync

Added in: v1.61 webStorage.SetItemAsync

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

Usage

await WebStorage.SetItemAsync(name, value);

Arguments

  • name string#

    Name of the item to set.

  • value string#

    New value for the item.

Returns