Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swimmwatch/playwright-localstorage
Extension for the Playwright package that allows access to the Web Storage API.
https://github.com/swimmwatch/playwright-localstorage
localstorage playwright playwright-python python sessionstorage
Last synced: 2 days ago
JSON representation
Extension for the Playwright package that allows access to the Web Storage API.
- Host: GitHub
- URL: https://github.com/swimmwatch/playwright-localstorage
- Owner: swimmwatch
- License: mit
- Created: 2024-07-22T10:01:09.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-01-10T09:22:32.000Z (10 days ago)
- Last Synced: 2025-01-10T10:35:35.530Z (10 days ago)
- Topics: localstorage, playwright, playwright-python, python, sessionstorage
- Language: Python
- Homepage:
- Size: 998 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# playwright-localstorage
![playwright-localstorage](https://socialify.git.ci/swimmwatch/playwright-localstorage/image?description=1&font=Raleway&language=1&name=1&owner=1&pattern=Brick%20Wall&theme=Dark)
Extension for the Playwright package
that allows access to the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).## Installation
```shell
pip install playwright-localstorage
```## Usage
### Synchronous
```python
from playwright.sync_api import Playwright
from playwright.sync_api import sync_playwrightfrom 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)```
### Asynchronous
The package supports asynchronous implementation.