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.

js
await page.goto('https://example.com');
await page.localStorage.setItem('token', 'abc');
const token = await page.localStorage.getItem('token');
const all = await page.localStorage.items();
await page.localStorage.removeItem('token');
await page.localStorage.clear();

Methods ​

webStorage.clear() ​

Added in: v1.61 async

Removes all items from the storage.

webStorage.getItem() ​

Added in: v1.61 async

Returns the value for the given name if present.

Arguments

  • name string

    Name of the item to retrieve.

Returns

  • Promise<null | string>

webStorage.items() ​

Added in: v1.61 async

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

Returns

  • Promise<Array<Object>>

webStorage.removeItem() ​

Added in: v1.61 async

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

Arguments

  • name string

    Name of the item to remove.

webStorage.setItem() ​

Added in: v1.61 async

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.