GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - HyperionGray/trio-chrome-devtools-protocol: Trio driver for Chrome DevTools Protocol (CDP)

BranchesTags
Open more actions menu

Latest commit

 

History

460 Commits
460 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
examples
examples
 
 
generator
generator
 
 
tests
tests
 
 
trio_cdp
trio_cdp
 
 
.bish-index
.bish-index
 
 
.bish.sqlite
.bish.sqlite
 
 
.gitignore
.gitignore
 
 
.readthedocs.yml
.readthedocs.yml
 
 
.travis.yml
.travis.yml
 
 
AGENTS.md
AGENTS.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
bfg-1.15.0.jar
bfg-1.15.0.jar
 
 
poetry.lock
poetry.lock
 
 
pyproject.toml
pyproject.toml
 
 
pytest.ini
pytest.ini
 
 
rules.json
rules.json
 
 

Repository files navigation

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.

Connecting to Chrome

Trio CDP supports two ways to connect to Chrome:

1. Using an HTTP URL (Recommended for automation)

The simplest way to connect is by using an HTTP URL. When Chrome is started with --remote-debugging-port=9222, you can connect using:

from trio_cdp import open_cdp

async with open_cdp('http://localhost:9222') as conn:
    # Your code here
    ...

The library will automatically discover the WebSocket URL from Chrome's HTTP endpoint.

2. Using a WebSocket URL directly

You can also provide a WebSocket URL directly:

async with open_cdp('ws://localhost:9222/devtools/browser/...') as conn:
    ...

3. Using the discovery function

For more control, use the find_chrome_debugger_url() function:

from trio_cdp import find_chrome_debugger_url, open_cdp

# Discover the WebSocket URL
browser_url = find_chrome_debugger_url(port=9222)

async with open_cdp(browser_url) as conn:
    ...

Example Usage

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, including examples for taking screenshots and monitoring network events.

About

Trio driver for Chrome DevTools Protocol (CDP)

Resources

Readme
MIT license
Activity
Custom properties

Stars

72 stars

Watchers

4 watching

Forks

18 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.