Skip to content

Freeze after connect #27

Description

@paulocoutinhox

Hi,

It is freezing after connect, see:

test.py:

import asyncio

from pycdp import cdp
from pycdp.asyncio import connect_cdp


async def main():
    conn = await connect_cdp("http://127.0.0.1:18792")
    print("Connected to CDP")
    target_id = await conn.execute(cdp.target.create_target("about:blank"))
    print("Created target")
    target_session = await conn.connect_session(target_id)
    print("Connected to target session")
    await target_session.execute(cdp.page.enable())
    print("Enabled page")

    with target_session.safe_wait_for(cdp.page.DomContentEventFired) as navigation:
        print("Navigating to https://chromedevtools.github.io/devtools-protocol/")
        await target_session.execute(
            cdp.page.navigate("https://chromedevtools.github.io/devtools-protocol/")
        )
        print("Navigated to https://chromedevtools.github.io/devtools-protocol/")
        await navigation
    print("Got document")
    dom = await target_session.execute(cdp.dom.get_document())
    print("Got document")
    node = await target_session.execute(cdp.dom.query_selector(dom.node_id, "p"))
    print("Got node")
    js_node = await target_session.execute(cdp.dom.resolve_node(node))
    print("Resolved node")
    print(
        (
            await target_session.execute(
                cdp.runtime.call_function_on(
                    "function() {return this.innerText;}",
                    js_node.object_id,
                    return_by_value=True,
                )
            )
        )[0].value
    )
    print("Closed page")
    await target_session.execute(cdp.page.close())
    print("Closed target session")
    await conn.close()
    print("Closed connection")


if __name__ == "__main__":
    asyncio.run(main())

TESTING:

python3 test.py
Connected to CDP # freeze here

Can you help me?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions