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.local_storage and page.session_storage.

python
await page.goto("https://example.com")
await page.local_storage.set_item("token", "abc")
token = await page.local_storage.get_item("token")
all = await page.local_storage.items()
await page.local_storage.remove_item("token")
await page.local_storage.clear()
python
page.goto("https://example.com")
page.local_storage.set_item("token", "abc")
token = page.local_storage.get_item("token")
all = page.local_storage.items()
page.local_storage.remove_item("token")
page.local_storage.clear()

Methods ​

web_storage.clear() ​

Added in: v1.61

Removes all items from the storage.

web_storage.get_item() ​

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

web_storage.items() ​

Added in: v1.61

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

Returns

  • Array<Object>

web_storage.remove_item() ​

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.

web_storage.set_item() ​

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.