Skip to main content

Chrome Debugging Protocol client

Project description

CProto is a Debugging Protocol client that supports Chrome, Chromium and Blink based browsers.

CProto provides you an advanced interface to interact with Chrome (or another supported browser) instance from your Python code. It’s greatly useful for automated testing, debugging, profiling or even complicated page crawling.

This project is under development. More updates are coming soon.

Getting Started

Installing CProto

Python 2.7 or 3.3+ is required to install CProto.

Install the latest version using pip:

$ pip install cproto

Running Chrome in Debug mode

Option 1: Run Chrome in Docker, also in Headless mode.

Option 2: Run Chrome on host machine:

# «chrome» should point to your installation of Chrome
chrome --remote-debugging-port=9222 "about:blank"

# If you haven't created alias for Chrome yet, you could set it on MacOS like that:
# For Chrome
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
# For Chrome Canary
alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"
# For Chromium
alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium"

API Docs

Chrome Debugging Protocol documentation.

CProto complies to official Chrome Debugging Protocol, which implicates CProto’s interface has the same API as Chrome Debugging Protocol. Consider this example:

from cproto import CProto


# Print event's response and close CProto connection
def on_load(response):
    print(response)
    cp.close()


# Create CProto instance and connect to a browser over CDP
cp = CProto(host='127.0.0.1', port=9222)
# Enable Page domain events
cp.Page.enable()
# Adds Page callback that's fired after is loaded
cp.Page.loadEventFired = on_load
# Navigate browser to Github
cp.Page.navigate(url='https://github.com')

In this example Page Domain API was used to navigate to any arbitrary URL. There are a whole bunch of other methods and events available for each Domain, you could browse all of them on the CDP documentation website.

Roadmap

  • ☒ Domains support

  • ☒ Methods support

  • ☒ Events support

Under consideration:

  • Asynchronous I/O support using asyncio

Headless Chrome in Docker

You could use Docker to run CProto with Chrome Headless mode on any major OS via command line interface.

# Clone the repository
$ git clone git@github.com:asyne/cproto.git

# Build Docker image for Chrome Headless
$ docker build -t chrome-headless cproto

# Run Docker Chrome Headless mode container with port 9222 being proxied to the host machine
$ docker run --rm -it --cap-add=SYS_ADMIN -p 9222:9222 chrome-headless

# That's all here. Chrome Debugging interface is now up and listening for connections.
# You could check it out by opening this link in your browser – http://localhost:9222.

Examples

Check out examples directory.

More examples are coming soon.

Project details


Download files

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

Source Distribution

cproto-0.7.2.tar.gz (90.1 kB view details)

Uploaded Source

Built Distribution

cproto-0.7.2-py2.py3-none-any.whl (92.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cproto-0.7.2.tar.gz.

File metadata

  • Download URL: cproto-0.7.2.tar.gz
  • Upload date:
  • Size: 90.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for cproto-0.7.2.tar.gz
Algorithm Hash digest
SHA256 07b4c879d4a9a35fe3c6c9c80bc116a35e7417b2159112a78d7d8a281911cd09
MD5 d947b4206683b87b1ceba569d4f8a5c1
BLAKE2b-256 a53bb69d285dd07e10fea0baf776af80e51360238af20f3dcaa28c4860cbc90c

See more details on using hashes here.

File details

Details for the file cproto-0.7.2-py2.py3-none-any.whl.

File metadata

  • Download URL: cproto-0.7.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 92.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for cproto-0.7.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ff69cfa5e1ed32ccdb6e7c315cc5a7dae7b4123a1452f2bbdb7c37814ece4906
MD5 5fe69ed2aec1d8baaae8fe5cceb84bde
BLAKE2b-256 92b015e70a946a36ff6be75dc72d592d947769846f17b9444907fdd0cfb4f37d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page