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.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
clear
Removes all items from the storage.
Usage
await webStorage.clear();
Returns
getItem
Returns the value for the given name if present.
Usage
await webStorage.getItem(name);
Arguments
-
namestringName of the item to retrieve.
Returns
items
Returns all items in the storage as name/value pairs.
Usage
await webStorage.items();
Returns
removeItem
Removes the item with the given name. No-op if the item is absent.
Usage
await webStorage.removeItem(name);
Arguments
-
namestringName of the item to remove.
Returns
setItem
Sets the value for the given name. Overwrites any existing value for that name.
Usage
await webStorage.setItem(name, value);
Arguments
Returns
© 2026 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-webstorage