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-protocolVerified import paths — ran on the pinned version, not inferred.
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`.
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.
Always start your Chrome/Chromium instance with `--remote-debugging-port=<port_number>`. For automation, consider using a dedicated headless instance.
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.
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.