Skip to main content

A Python implementation version of Playwright's HAR tracer

Project description

playwright-har-tracer

PyPI version Python CI Coverage Status

A Python implementation version of Playwright's HAR tracer. It is equivalent to playwright v0.13.x’s HAR tracer implementation.

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

pip install playwright-har-tracer

Usage

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playwright-har-tracer-0.3.2.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

playwright_har_tracer-0.3.2-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page