Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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)




PyPI


Supported Python Versions




License


Code style


Linter


Type checker


Package health




Tests


Coverage


Release


Docs


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_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)

```

### Asynchronous

The package supports asynchronous implementation.