Skip to main content

Lightweight Chrome Debug Protocol (CDP) client for solveit

Project description

solvecdp

fastcdp provides an async Python client for the Chrome DevTools Protocol (CDP) over solveit’s js bridge. It exposes every CDP domain as a Python attribute with auto-generated signatures and docstrings — e.g. await cdp.page.navigate(url=...).

It includes event subscription via cdp.on()/cdp.wait_event(), navigation helpers (goto, wait_for_selector, wait_for), screenshot capture, and accessibility tree access. A cdp_search utility lets you search CDP commands by name or description. For use inside safepyrun sandboxes, cdp_yolo() registers all CDP classes.

Installation

You must install the solveit-chrome extension before using solvecdp.

Solveit already has solvecdp installed, but if you want to install the latest you can get it from pypi:

$ pip install solvecdp

How to use

from solvecdp import *

The JsCDP class

Every CDP domain is available as an attribute with auto-generated signatures. You can search for commands with cdp_search:

cdp_search('screenshot')
"Emulation.setVisibleSize: Resizes the frame/viewport of the page. Note that this does not affect the frame's container\n(e.g. browser window). Can \nHeadlessExperimental.beginFrame: Sends a BeginFrame to the target and returns when the frame was completed. Optionally captures a\nscreenshot from the res\n  evt Overlay.screenshotRequested: Fired when user asks to capture screenshot of some area on the page.\nPage.captureScreenshot: Capture page screenshot."

Create a new page:

jc = await JsCDP.new()

Go to a page:

await jc.goto('https://httpbin.org/forms/post')

Eval js:

await jc.eval('document.title')
'6. httpbin.org/forms/post'

Or you can wait_for any js expression to be truthy, and have it returned:

await jc.wait_for('document.title')
'6. httpbin.org/forms/post'

Take a screenshot of the page:

img = await jc.screenshot()

Clean up when done:

await jc.close()

See JsCDP docs for full details.

Filling forms

page = await JsCDP.new(url='https://httpbin.org/forms/post')

For finding elements to interact with, use ax_tree:

root = await page.ax_tree()
print(str(root)[:300])
- **RootWebArea** "6. httpbin.org/forms/post" `focusable=True` `url=https://httpbin.org/forms/post` [#14]
  - **LabelText** "" [#20]
    - **StaticText** "Customer name: " [#62]
      - **InlineTextBox** "Customer name: "
    - **textbox** "Customer name: " `focusable=True` `editable=plaintext` `set

find and find_id are used to identify elements in the tree:

nmid = root.find_id('textbox', 'Customer name')
nmid
2

You can use regular CDP methods, or one of the provided shortcuts:

await page.fill_text(nmid, 'Jeremy Howard')
await page.click(root.find_id('radio', 'Large'))
await page.js_node_run('this.value = "18:30"', root.find_id('InputTime', 'delivery time'));

You can use click to click a button, or click_and_wait to wait for the next page to load:

await page.click_and_wait(root.find_id('button', 'Submit order'))
await page.close()

To allow LLMs like solveit with safepyrun to access solvecdp, use:

cdp_yolo()

Then use a prompt such as:

Try using pyrun to create a page_ JsCDP object, then goto <url>, fill it out, read it to check it’s filled correctly, then submit it, and see what you get back. Don’t use find_id - you can get all the ids at once with ax_tree (don’t truncate the result of it). Don’t add extra waits etc - solvecdp handles it automatically. IDs can change so be sure to use the ax_tree IDs you read.

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

solvecdp-0.0.4.tar.gz (178.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solvecdp-0.0.4-py3-none-any.whl (181.9 kB view details)

Uploaded Python 3

File details

Details for the file solvecdp-0.0.4.tar.gz.

File metadata

  • Download URL: solvecdp-0.0.4.tar.gz
  • Upload date:
  • Size: 178.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for solvecdp-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e023c772e51f954d0699076c6bd72065b581fd3d24ae04e28fc2b51cb562199d
MD5 19c2b8c2e941d5bb173a3d1a437fdfae
BLAKE2b-256 bcde6ce78b9b484c0a8d3b2dbc41ce07a02c54364f68a363da23a47f7b8a0483

See more details on using hashes here.

File details

Details for the file solvecdp-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: solvecdp-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 181.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for solvecdp-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4faccbb92ac0092eeb9a53895c6d59a3adbd25714e033df9a666eb15b18eb63e
MD5 e64b2a65c69a9afe32737161e703ebba
BLAKE2b-256 7921d2b871d197dd5d7eabb803f742c0b1720cffbd1dc3f209289f8d458c220c

See more details on using hashes here.

Supported by

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