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.61Removes all items from the storage.
Usage
await WebStorage.ClearAsync();
Returns
GetItemAsync
Added in: v1.61Returns the value for the given name if present.
Usage
await WebStorage.GetItemAsync(name);
Arguments
Returns
ItemsAsync
Added in: v1.61Returns all items in the storage as name/value pairs.
Usage
await WebStorage.ItemsAsync();
Returns
- IReadOnlyList<Items>#
RemoveItemAsync
Added in: v1.61Removes the item with the given name. No-op if the item is absent.
Usage
await WebStorage.RemoveItemAsync(name);
Arguments
Returns
SetItemAsync
Added in: v1.61Sets the value for the given name. Overwrites any existing value for that name.
Usage
await WebStorage.SetItemAsync(name, value);
Arguments
Returns