Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ class CDPRegistrationLibrary:
### Regenerating Types

```bash
# Using task (recommended)
task generate

# Or directly with uv
uv run python -m cdp_use.generator

# Or with python
python -m cdp_use.generator
```

Expand All @@ -215,6 +222,32 @@ This will:
3. Create domain-specific client classes
4. Format the code

### Version Pinning

By default, the generator downloads the latest CDP specification from the master branch. To pin a specific version, edit `cdp_use/generator/constants.py`:

```python
# Pin to a specific commit
CDP_VERSION = "4b0c3f2e8c5d6a7b9e1f2a3c4d5e6f7a8b9c0d1e"

# Or use master for latest
CDP_VERSION = "refs/heads/master"
```

To find specific commits, visit: https://github.com/ChromeDevTools/devtools-protocol/commits/master

### Available Tasks

```bash
task generate # Regenerate CDP types from protocol definitions
task build # Build the distribution package
task lint # Run ruff linter
task format # Format code with ruff
task format-json # Format JSON protocol files
task example # Run the simple example
task clean # Clean generated files and build artifacts
```

### Project Structure

```
Expand Down
47 changes: 47 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "3"

tasks:
generate:
desc: "Regenerate CDP types from protocol definitions"
cmds:
- uv run python -m cdp_use.generator

build:
desc: "Build the distribution package"
cmds:
- uv build

install:
desc: "Install package in development mode"
cmds:
- uv pip install -e .

lint:
desc: "Run ruff linter"
cmds:
- uv run ruff check cdp_use/ --statistics

format:
desc: "Format code with ruff"
cmds:
- uv run ruff format cdp_use/

format-json:
desc: "Format JSON protocol files"
cmds:
- |
for file in cdp_use/custom_protocols/*.json; do
Copy link

@cubic-dev-ai cubic-dev-ai bot Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format-json fails when no custom protocol files exist because the unmatched glob is treated as a literal path. Add a guard so the loop skips/terminates when no files match.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Taskfile.yml, line 33:

<comment>format-json fails when no custom protocol files exist because the unmatched glob is treated as a literal path. Add a guard so the loop skips/terminates when no files match.</comment>

<file context>
@@ -0,0 +1,46 @@
+    desc: &quot;Format JSON protocol files&quot;
+    cmds:
+      - |
+        for file in cdp_use/custom_protocols/*.json; do
+          python3 -m json.tool &quot;$file&quot; &quot;$file.tmp&quot; &amp;&amp; mv &quot;$file.tmp&quot; &quot;$file&quot;
+        done
</file context>

✅ Addressed in b3ee5c0

[ -f "$file" ] || continue
python3 -m json.tool "$file" "$file.tmp" && mv "$file.tmp" "$file"
done

example:
desc: "Run the simple example"
cmds:
- uv run python simple.py

clean:
desc: "Clean generated files and build artifacts"
cmds:
- rm -rf dist/ build/ *.egg-info
- find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
42 changes: 22 additions & 20 deletions cdp_use/cdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,51 @@
from . import accessibility
from . import animation
from . import audits
from . import extensions
from . import autofill
from . import backgroundservice
from . import bluetoothemulation
from . import browser
from . import css
from . import cachestorage
from . import cast
from . import dom
from . import domdebugger
from . import eventbreakpoints
from . import domsnapshot
from . import domstorage
from . import deviceaccess
from . import deviceorientation
from . import emulation
from . import eventbreakpoints
from . import extensions
from . import fedcm
from . import fetch
from . import filesystem
from . import headlessexperimental
from . import io
from . import filesystem
from . import indexeddb
from . import input
from . import inspector
from . import layertree
from . import log
from . import media
from . import memory
from . import network
from . import overlay
from . import pwa
from . import page
from . import performance
from . import performancetimeline
from . import preload
from . import security
from . import serviceworker
from . import storage
from . import systeminfo
from . import target
from . import tethering
from . import tracing
from . import fetch
from . import webaudio
from . import webauthn
from . import media
from . import deviceaccess
from . import preload
from . import fedcm
from . import pwa
from . import bluetoothemulation
from . import browseruse

from .library import CDPLibrary
from .registry import EventRegistry
Expand All @@ -72,50 +73,51 @@
"accessibility",
"animation",
"audits",
"extensions",
"autofill",
"backgroundservice",
"bluetoothemulation",
"browser",
"css",
"cachestorage",
"cast",
"dom",
"domdebugger",
"eventbreakpoints",
"domsnapshot",
"domstorage",
"deviceaccess",
"deviceorientation",
"emulation",
"eventbreakpoints",
"extensions",
"fedcm",
"fetch",
"filesystem",
"headlessexperimental",
"io",
"filesystem",
"indexeddb",
"input",
"inspector",
"layertree",
"log",
"media",
"memory",
"network",
"overlay",
"pwa",
"page",
"performance",
"performancetimeline",
"preload",
"security",
"serviceworker",
"storage",
"systeminfo",
"target",
"tethering",
"tracing",
"fetch",
"webaudio",
"webauthn",
"media",
"deviceaccess",
"preload",
"fedcm",
"pwa",
"bluetoothemulation",
"browseruse",
"CDPLibrary",
"EventRegistry",
"CDPRegistrationLibrary",
Expand Down
6 changes: 1 addition & 5 deletions cdp_use/cdp/accessibility/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .types import AXNode
from .types import AXNodeId


class GetPartialAXTreeParameters(TypedDict, total=False):
nodeId: "NodeId"
"""Identifier of the node to get the partial accessibility tree for."""
Expand All @@ -34,7 +35,6 @@ class GetPartialAXTreeReturns(TypedDict):
children, if requested."""



class GetFullAXTreeParameters(TypedDict, total=False):
depth: "int"
"""The maximum depth at which descendants of the root node should be retrieved.
Expand All @@ -48,7 +48,6 @@ class GetFullAXTreeReturns(TypedDict):
nodes: "List[AXNode]"



class GetRootAXNodeParameters(TypedDict, total=False):
frameId: "FrameId"
"""The frame in whose document the node resides.
Expand All @@ -59,7 +58,6 @@ class GetRootAXNodeReturns(TypedDict):
node: "AXNode"



class GetAXNodeAndAncestorsParameters(TypedDict, total=False):
nodeId: "NodeId"
"""Identifier of the node to get."""
Expand All @@ -73,7 +71,6 @@ class GetAXNodeAndAncestorsReturns(TypedDict):
nodes: "List[AXNode]"



class GetChildAXNodesParameters(TypedDict):
id: "AXNodeId"
frameId: "NotRequired[FrameId]"
Expand All @@ -85,7 +82,6 @@ class GetChildAXNodesReturns(TypedDict):
nodes: "List[AXNode]"



class QueryAXTreeParameters(TypedDict, total=False):
nodeId: "NodeId"
"""Identifier of the node for the root to query."""
Expand Down
5 changes: 4 additions & 1 deletion cdp_use/cdp/accessibility/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

"""The loadComplete event mirrors the load complete event sent by the browser to assistive
technology when the web page has finished loading."""


class LoadCompleteEvent(TypedDict):
root: "AXNode"
"""New document root node."""



"""The nodesUpdated event is sent every time a previously requested node has changed the in tree."""


class NodesUpdatedEvent(TypedDict):
nodes: "List[AXNode]"
"""Updated node data."""
Loading
Loading