Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Trio driver for Chrome DevTools Protocol (CDP)

Project description

Trio CDP

PyPI Python Versions MIT License Build Status Read the Docs

This Python library performs remote control of any web browser that implements the Chrome DevTools Protocol. It is built using the type wrappers in python-chrome-devtools-protocol and implements I/O using Trio. This library handles the WebSocket negotiation and session management, allowing you to transparently multiplex commands, responses, and events over a single connection.

The example below demonstrates the salient features of the library by navigating to a web page and extracting the document title.

from trio_cdp import open_cdp, page, dom

async with open_cdp(cdp_url) as conn:
    # Find the first available target (usually a browser tab).
    targets = await target.get_targets()
    target_id = targets[0].id

    # Create a new session with the chosen target.
    async with conn.open_session(target_id) as session:

        # Navigate to a website.
        async with session.page_enable()
        async with session.wait_for(page.LoadEventFired):
            await session.execute(page.navigate(target_url))

        # Extract the page title.
        root_node = await session.execute(dom.get_document())
        title_node_id = await session.execute(dom.query_selector(root_node.node_id,
            'title'))
        html = await session.execute(dom.get_outer_html(title_node_id))
        print(html)

This example code is explained in the documentation and more example code can be found in the examples/ directory of this repository.

Project details


Download files

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

Files for trio-chrome-devtools-protocol, version 0.6.0
Filename, size File type Python version Upload date Hashes
Filename, size trio_chrome_devtools_protocol-0.6.0-py3-none-any.whl (79.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size trio-chrome-devtools-protocol-0.6.0.tar.gz (57.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page