An async Python interface for Chrome Devtools
Project description
cdipy
Chrome Devtools Interface that instruments Chrome via the devtools protocol.
Meant to serve as a pythonic version of chrome-remote-interface.
Example Usage
import asyncio
import base64
import logging
import sys
from cdipy import ChromeDevTools
from cdipy import ChromeDevToolsTarget
from cdipy import ChromeRunner
LOGGER = logging.getLogger("cdipy.scripts.screenshot")
FILENAME = "screenshot.png"
async def async_main(url):
# Start Chrome
chrome = ChromeRunner()
await chrome.launch()
# Connect to devtools websocket
cdi = ChromeDevTools(chrome.websocket_uri)
await cdi.connect()
# Create a new target and attach to it
target = await cdi.Target.createTarget(url="about:blank")
session = await cdi.Target.attachToTarget(targetId=target["targetId"])
# Create a ChromeDevToolsTarget class to handle target messages
cdit = ChromeDevToolsTarget(cdi, session["sessionId"])
# Enable 'Page' events
await cdit.Page.enable()
# Navigate to URL
LOGGER.info("Navigating to %s", url)
await cdit.Page.navigate(url=url)
# Wait for the Page.loadEventFired event
# This may not ever fire on some pages, so it's good to set a limit
try:
await cdit.wait_for("Page.loadEventFired", 10)
except asyncio.TimeoutError:
print("Loaded event never fired!")
# Take a screenshot
screenshot_response = await cdit.Page.captureScreenshot(format="png")
screenshot_bytes = base64.b64decode(screenshot_response["data"])
with open(FILENAME, "w+b") as fileobj:
fileobj.write(screenshot_bytes)
LOGGER.info("wrote %s", FILENAME)
def main():
logging.basicConfig(level=logging.INFO)
asyncio.run(async_main(sys.argv[1]))
if __name__ == "__main__":
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdipy-0.4.3.tar.gz.
File metadata
- Download URL: cdipy-0.4.3.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb85622efdf5a09c7050aae47b3bf8c953cd20130917af73ac5ff7ff162afa8
|
|
| MD5 |
ee7b05d740e7650abfb405f2a5f8c02f
|
|
| BLAKE2b-256 |
43f58a01257c2f74be3f44337a89e3233491d4636824070d2c3411d22f30e7f9
|
Provenance
The following attestation bundles were made for cdipy-0.4.3.tar.gz:
Publisher:
publish-to-pypi.yml on pilate/cdipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdipy-0.4.3.tar.gz -
Subject digest:
dbb85622efdf5a09c7050aae47b3bf8c953cd20130917af73ac5ff7ff162afa8 - Sigstore transparency entry: 711270797
- Sigstore integration time:
-
Permalink:
pilate/cdipy@839be691e645475a0a839d560d59e5cad1bf66ff -
Branch / Tag:
refs/tags/0.4.3 - Owner: https://github.com/pilate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@839be691e645475a0a839d560d59e5cad1bf66ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file cdipy-0.4.3-py3-none-any.whl.
File metadata
- Download URL: cdipy-0.4.3-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e72847819e5e95c544403e39d28d4add70bd9b734a14a6623df5d44c22ba12b5
|
|
| MD5 |
23d4201706a34359b0bdd0b932c86082
|
|
| BLAKE2b-256 |
ea53657e00cc2987cfa82ff65f80c76532b10aa802d3c96211f059ee8c0a14d8
|
Provenance
The following attestation bundles were made for cdipy-0.4.3-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on pilate/cdipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdipy-0.4.3-py3-none-any.whl -
Subject digest:
e72847819e5e95c544403e39d28d4add70bd9b734a14a6623df5d44c22ba12b5 - Sigstore transparency entry: 711270858
- Sigstore integration time:
-
Permalink:
pilate/cdipy@839be691e645475a0a839d560d59e5cad1bf66ff -
Branch / Tag:
refs/tags/0.4.3 - Owner: https://github.com/pilate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@839be691e645475a0a839d560d59e5cad1bf66ff -
Trigger Event:
push
-
Statement type: