Registry / http-networking / trio-chrome-devtools-protocol

trio-chrome-devtools-protocol

JSON →
library0.6.0pypypiunverified

Trio Chrome DevTools Protocol (Trio CDP) is a Python library that enables remote control of any web browser implementing the Chrome DevTools Protocol. It leverages Trio for asynchronous I/O and `python-chrome-devtools-protocol` for type wrappers. The library handles WebSocket negotiation and session management, allowing transparent multiplexing of commands, responses, and events over a single connection. The current version is 0.6.0, released in April 2020, with ongoing maintenance evident through recent GitHub activity.

pip install trio-chrome-devtools-protocol
INSTALL
IMPORT
SIG · TRIO-CHROME-DEVTOO
T
trio-chrome-devtools-protocol
http-networkingpythonv0.6.0
Install
5.7s avg
Import
875ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.559s · 33.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.7s · import 0.491s · 35MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

open_cdp
from trio_cdp import open_cdp
from trio_cdp import open_cdp

This quickstart connects to a headless Chrome instance (assumed to be running on `http://localhost:9222`), navigates to a specified URL, waits for the page to load, and then extracts the HTML content of the page's title element. It demonstrates basic connection, session management, navigation, and DOM interaction using Trio's async capabilities. Before running, ensure Chrome is launched with `--remote-debugging-port=9222`.

import trio from trio_cdp import open_cdp, page, dom async def main(): # Ensure Chrome is running with --remote-debugging-port=9222 cdp_url = 'http://localhost:9222' target_url = 'https://www.example.com' try: async with open_cdp(cdp_url) as conn: # Find the first available target (usually a browser tab). # Note: target domain imports are typically implicitly available on 'conn.target' targets = await conn.target.get_targets() if not targets: print('No targets found. Is Chrome running and a page open?') return target_id = targets[0].id # Create a new session with the chosen target. async with conn.open_session(target_id) as session: # Enable page-level events to wait for navigation completion. async with session.page_enable(): async with session.wait_for(page.LoadEventFired): await session.execute(page.navigate(target_url)) print(f"Navigated to: {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')) if title_node_id: html = await session.execute(dom.get_outer_html(title_node_id)) print(f"Page Title HTML: {html}") else: print("Could not find title element.") except Exception as e: print(f"An error occurred: {e}") print("Make sure Chrome is running with '--remote-debugging-port=9222'.") if __name__ == '__main__': trio.run(main)
Debug
Known issues
breakingThe Chrome DevTools Protocol itself is subject to frequent changes, especially the 'tip-of-tree' version. As `trio-chrome-devtools-protocol` relies on `python-chrome-devtools-protocol` (which generates its types from CDP), changes in the underlying protocol can lead to API mismatches or breakage if the library is not updated to match the browser's CDP version.
fix
Pin your browser version (e.g., Chrome, Chromium) to a specific, known-compatible version with the library. Regularly check for updates to `trio-chrome-devtools-protocol` and `python-chrome-devtools-protocol` and consult their changelogs when upgrading browser or library versions.
affects: All versions
gotchaChrome/Chromium must be launched with the `--remote-debugging-port` flag (e.g., `--remote-debugging-port=9222`) for `trio-chrome-devtools-protocol` to connect. Without this, the browser will not expose the DevTools Protocol endpoint, leading to connection failures.
fix
Always start your Chrome/Chromium instance with `--remote-debugging-port=<port_number>`. For automation, consider using a dedicated headless instance.
affects: All versions
gotchaTo receive events (e.g., `page.LoadEventFired`, `network.RequestWillBeSent`), you must explicitly enable the corresponding CDP domain using methods like `session.page_enable()` or `session.network_enable()` before the event occurs. Events are not enabled by default.
fix
Call the appropriate `_enable()` method for the domain from which you expect events (e.g., `await session.page_enable()` for `page` events) at the beginning of your session or before the relevant actions.
affects: All versions
gotchaAs `trio-chrome-devtools-protocol` is built on Trio, all asynchronous operations must be executed within a Trio event loop. Attempting to call `async` functions outside `trio.run()` or a `trio.lowlevel.checkpoint()` context will result in runtime errors.
fix
Ensure your main application entry point uses `trio.run()` to start the event loop, and all `await` calls are within `async def` functions managed by Trio.
affects: All versions
Upgrade
Version history
0.6.0latest on PyPI · released Apr 14, 2020
Audit
Dependencies
python-chrome-devtools-protocolrequiredProvides Python type wrappers for CDP commands and events, foundational for this library's functionality.
triorequiredThe asynchronous I/O framework used by this library for network operations.
PythonrequiredRequired Python version.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
trio-chrome-devtools-protocol — pip install trio-chrome-devtools-protocol · libregistry