Skip to content

WebStorage ​

Added in: v1.61

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.

csharp
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 ​

WebStorage.ClearAsync() ​

Added in: v1.61

Removes all items from the storage.

WebStorage.GetItemAsync() ​

Added in: v1.61

Returns the value for the given name if present.

Arguments

  • name string

    Name of the item to retrieve.

Returns

  • null | string

WebStorage.ItemsAsync() ​

Added in: v1.61

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

Returns

  • Array<Object>

WebStorage.RemoveItemAsync() ​

Added in: v1.61

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

Arguments

  • name string

    Name of the item to remove.

WebStorage.SetItemAsync() ​

Added in: v1.61

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

Arguments

  • name string

    Name of the item to set.

  • value string

    New value for the item.

Released under the Apache 2.0 License.