Metadata-Version: 2.1
Name: playwright-har-tracer
Version: 0.1.0
Summary: A Python implementation version of Playwright's HAR tracer
Home-page: https://github.com/ninoseki/playwright-har-tracer
Author: Manabu Niseki
Author-email: manabu.niseki@gmail.com
Requires-Python: >=3.8,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: dataclasses-json (>=0.5.3,<0.6.0)
Requires-Dist: poetry-version (>=0.1.5,<0.2.0)
Requires-Dist: python-dateutil (>=2.8.1,<3.0.0)
Requires-Dist: stringcase (>=1.2.0,<2.0.0)
Project-URL: Repository, https://github.com/ninoseki/playwright-har-tracer
Description-Content-Type: text/markdown

# playwright-har-tracer

A Python implementation version of Playwright's HAR tracer.

## Motivation

Playwright's HAR tracer is implemented to generate HAR as a file. I need to get HAR as a Python object rather than a file.

- `playwright-har-tracer`'s HarTracer generates HAR as a dataclass object.

## ⚠️ Limitations

- Tested with Python 3.8+
- Tested with Chromium only
- Supports the async API only

## Installation

```bash
pip install playwright-har-tracer
```

## Usage

```python
import asyncio
from playwright.async_api import async_playwright
from playwright_har_tracer import HarTracer


async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        context = await browser.new_context()

        tracer = HarTracer(context=context, browser_name=p.chromium.name)

        page = await context.new_page()

        await page.goto("http://whatsmyuseragent.org/")

        har = await tracer.flush()

        await context.close()
        await browser.close()

    print(har.to_json())


asyncio.run(main())
```

