Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental feature: heap snapshots #126

Open
simonw opened this issue Nov 1, 2023 · 1 comment
Open

Experimental feature: heap snapshots #126

simonw opened this issue Nov 1, 2023 · 1 comment
Labels
enhancement New feature or request research

Comments

@simonw
Copy link
Owner

simonw commented Nov 1, 2023

Here's the prototype:

@cli.command()
@click.argument("url")
@click.option(
    "-a",
    "--auth",
    type=click.File("r"),
    help="Path to JSON authentication context file",
)
def snapshot(url, auth):
    "Return a heap snapshot of the specified URL"
    url = url_or_file_path(url, _check_and_absolutize)
    with sync_playwright() as p:
        context, browser_obj = _browser_context(
            p,
            auth,
            # browser=browser,
            # user_agent=user_agent,
            # reduced_motion=reduced_motion,
        )
        page = context.new_page()
        client = page.context.new_cdp_session(page)

        chunks = []

        def store_chunk(chunk):
            chunks.append(chunk["chunk"])

        client.on("HeapProfiler.addHeapSnapshotChunk", store_chunk)

        page.goto(url)

        client.send("HeapProfiler.takeHeapSnapshot", {})

        combined = "".join(chunks)
        data = json.loads(combined)
        click.echo(json.dumps(data, indent=2))
@simonw simonw added enhancement New feature or request research labels Nov 1, 2023
@byt3bl33d3r
Copy link

@simonw I've ported the original project to Python & Playwright https://github.com/byt3bl33d3r/playwright-heap-snapshot

Feel free to steal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request research
Projects
None yet
Development

No branches or pull requests

2 participants