Extension for the Playwright package that allows access to the Web Storage API.
pip install playwright-localstorage
from playwright.sync_api import Playwright
from playwright.sync_api import sync_playwright
from playwright_localstorage import LocalStorageAccessor
def run(p: Playwright):
chromium = p.chromium
browser = chromium.launch(headless=False)
page = browser.new_page()
page.goto("http://example.com")
accessor = LocalStorageAccessor(page)
accessor.set("token", "secret-token") # Set value
token = accessor.get("token") # Get value
print(token) # >> "secret-token"
exists = accessor.has("token") # Check key for existence
print(exists) # >> True
keys = accessor.keys() # Get all keys
print(keys) # >> ["token"]
items = accessor.items() # Get all items
print(items) # >> {"token": "secret-token"}
accessor.remove("token") # Remove key
exists = accessor.has("token")
print(exists) # >> False
browser.close()
with sync_playwright() as playwright:
run(playwright)
The package supports asynchronous implementation.