cdpwave 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cdpwave-0.1.0/.github/workflows/ci.yml +42 -0
- cdpwave-0.1.0/.github/workflows/docs.yml +33 -0
- cdpwave-0.1.0/.github/workflows/release.yml +64 -0
- cdpwave-0.1.0/.github/workflows/test.yml +30 -0
- cdpwave-0.1.0/.gitignore +25 -0
- cdpwave-0.1.0/LICENSE +21 -0
- cdpwave-0.1.0/Makefile +27 -0
- cdpwave-0.1.0/PKG-INFO +94 -0
- cdpwave-0.1.0/README.md +58 -0
- cdpwave-0.1.0/cdpwave/__init__.py +34 -0
- cdpwave-0.1.0/cdpwave/browser/__init__.py +0 -0
- cdpwave-0.1.0/cdpwave/browser/discovery.py +86 -0
- cdpwave-0.1.0/cdpwave/browser/finder.py +130 -0
- cdpwave-0.1.0/cdpwave/browser/launcher.py +170 -0
- cdpwave-0.1.0/cdpwave/client.py +332 -0
- cdpwave-0.1.0/cdpwave/domains/__init__.py +0 -0
- cdpwave-0.1.0/cdpwave/domains/base.py +15 -0
- cdpwave-0.1.0/cdpwave/domains/console.py +14 -0
- cdpwave-0.1.0/cdpwave/domains/dom.py +92 -0
- cdpwave-0.1.0/cdpwave/domains/log.py +26 -0
- cdpwave-0.1.0/cdpwave/domains/network.py +141 -0
- cdpwave-0.1.0/cdpwave/domains/page.py +86 -0
- cdpwave-0.1.0/cdpwave/domains/runtime.py +71 -0
- cdpwave-0.1.0/cdpwave/domains/target.py +40 -0
- cdpwave-0.1.0/cdpwave/events/__init__.py +0 -0
- cdpwave-0.1.0/cdpwave/events/dispatcher.py +44 -0
- cdpwave-0.1.0/cdpwave/events/handlers.py +37 -0
- cdpwave-0.1.0/cdpwave/exceptions.py +40 -0
- cdpwave-0.1.0/cdpwave/session/__init__.py +0 -0
- cdpwave-0.1.0/cdpwave/session/manager.py +32 -0
- cdpwave-0.1.0/cdpwave/transport/__init__.py +0 -0
- cdpwave-0.1.0/cdpwave/transport/connection.py +142 -0
- cdpwave-0.1.0/cdpwave/transport/correlation.py +37 -0
- cdpwave-0.1.0/cdpwave/transport/serializer.py +33 -0
- cdpwave-0.1.0/cdpwave/types.py +8 -0
- cdpwave-0.1.0/docs/api/client.md +5 -0
- cdpwave-0.1.0/docs/api/domains.md +29 -0
- cdpwave-0.1.0/docs/api/events.md +13 -0
- cdpwave-0.1.0/docs/api/exceptions.md +3 -0
- cdpwave-0.1.0/docs/api/session.md +3 -0
- cdpwave-0.1.0/docs/cookbook/connect-existing.md +60 -0
- cdpwave-0.1.0/docs/cookbook/custom-flags.md +70 -0
- cdpwave-0.1.0/docs/cookbook/error-handling.md +102 -0
- cdpwave-0.1.0/docs/cookbook/escape-hatch.md +105 -0
- cdpwave-0.1.0/docs/cookbook/headless.md +69 -0
- cdpwave-0.1.0/docs/guide/browser-launch.md +98 -0
- cdpwave-0.1.0/docs/guide/dom.md +97 -0
- cdpwave-0.1.0/docs/guide/evaluation.md +97 -0
- cdpwave-0.1.0/docs/guide/events.md +102 -0
- cdpwave-0.1.0/docs/guide/installation.md +63 -0
- cdpwave-0.1.0/docs/guide/multi-tab.md +92 -0
- cdpwave-0.1.0/docs/guide/navigation.md +102 -0
- cdpwave-0.1.0/docs/guide/network.md +135 -0
- cdpwave-0.1.0/docs/guide/screenshots.md +107 -0
- cdpwave-0.1.0/docs/index.md +46 -0
- cdpwave-0.1.0/docs/migration/pychrome.md +74 -0
- cdpwave-0.1.0/docs/migration/pyppeteer.md +81 -0
- cdpwave-0.1.0/docs/quickstart.md +114 -0
- cdpwave-0.1.0/mkdocs.yml +91 -0
- cdpwave-0.1.0/pyproject.toml +73 -0
- cdpwave-0.1.0/tests/__init__.py +0 -0
- cdpwave-0.1.0/tests/conftest.py +5 -0
- cdpwave-0.1.0/tests/integration/__init__.py +0 -0
- cdpwave-0.1.0/tests/integration/conftest.py +48 -0
- cdpwave-0.1.0/tests/integration/test_cookies.py +64 -0
- cdpwave-0.1.0/tests/integration/test_dom.py +111 -0
- cdpwave-0.1.0/tests/integration/test_escape_hatch.py +31 -0
- cdpwave-0.1.0/tests/integration/test_events.py +162 -0
- cdpwave-0.1.0/tests/integration/test_hello_world.py +35 -0
- cdpwave-0.1.0/tests/integration/test_lifecycle.py +62 -0
- cdpwave-0.1.0/tests/integration/test_multi_page.py +70 -0
- cdpwave-0.1.0/tests/integration/test_navigation.py +46 -0
- cdpwave-0.1.0/tests/integration/test_network.py +84 -0
- cdpwave-0.1.0/tests/integration/test_pdf.py +33 -0
- cdpwave-0.1.0/tests/integration/test_screenshot.py +57 -0
- cdpwave-0.1.0/tests/unit/__init__.py +0 -0
- cdpwave-0.1.0/tests/unit/domains/__init__.py +0 -0
- cdpwave-0.1.0/tests/unit/domains/test_domains.py +249 -0
- cdpwave-0.1.0/tests/unit/domains/test_new_domains.py +349 -0
- cdpwave-0.1.0/tests/unit/fake_sender.py +31 -0
- cdpwave-0.1.0/tests/unit/test_client.py +209 -0
- cdpwave-0.1.0/tests/unit/test_connection.py +212 -0
- cdpwave-0.1.0/tests/unit/test_correlation.py +95 -0
- cdpwave-0.1.0/tests/unit/test_discovery.py +85 -0
- cdpwave-0.1.0/tests/unit/test_events.py +369 -0
- cdpwave-0.1.0/tests/unit/test_exceptions.py +54 -0
- cdpwave-0.1.0/tests/unit/test_finder.py +94 -0
- cdpwave-0.1.0/tests/unit/test_launcher.py +90 -0
- cdpwave-0.1.0/tests/unit/test_robustness.py +363 -0
- cdpwave-0.1.0/tests/unit/test_serializer.py +92 -0
- cdpwave-0.1.0/tests/unit/test_session_manager.py +57 -0
- cdpwave-0.1.0/tests/unit/transport/__init__.py +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.12"
|
|
17
|
+
- run: pip install -e ".[dev]"
|
|
18
|
+
- run: ruff check .
|
|
19
|
+
- run: mypy cdpwave/
|
|
20
|
+
|
|
21
|
+
unit-tests:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- run: pip install -e ".[dev]"
|
|
29
|
+
- run: pytest tests/unit/ -v --cov=cdpwave --cov-report=term-missing
|
|
30
|
+
|
|
31
|
+
integration-tests:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
- uses: actions/setup-python@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.12"
|
|
38
|
+
- uses: browser-actions/setup-chrome@v1
|
|
39
|
+
with:
|
|
40
|
+
chrome-version: stable
|
|
41
|
+
- run: pip install -e ".[dev]"
|
|
42
|
+
- run: pytest tests/integration/ -m integration -v
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
pages: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: "pages"
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
docs:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
environment:
|
|
20
|
+
name: github-pages
|
|
21
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v5
|
|
24
|
+
- uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.12"
|
|
27
|
+
- run: pip install -e ".[docs]"
|
|
28
|
+
- run: mkdocs build --strict
|
|
29
|
+
- uses: actions/upload-pages-artifact@v3
|
|
30
|
+
with:
|
|
31
|
+
path: site
|
|
32
|
+
- id: deployment
|
|
33
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
contents: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v5
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
- run: pip install -e ".[dev]"
|
|
21
|
+
- run: ruff check .
|
|
22
|
+
- run: mypy cdpwave/
|
|
23
|
+
- run: pytest tests/unit/ -c pyproject.toml
|
|
24
|
+
- run: python -m build
|
|
25
|
+
- uses: actions/upload-artifact@v4
|
|
26
|
+
with:
|
|
27
|
+
name: dist
|
|
28
|
+
path: dist/
|
|
29
|
+
|
|
30
|
+
publish-pypi:
|
|
31
|
+
needs: build
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
environment: pypi
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/download-artifact@v5
|
|
36
|
+
with:
|
|
37
|
+
name: dist
|
|
38
|
+
path: dist/
|
|
39
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
40
|
+
|
|
41
|
+
github-release:
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
permissions:
|
|
45
|
+
contents: write
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v5
|
|
48
|
+
- uses: actions/download-artifact@v5
|
|
49
|
+
with:
|
|
50
|
+
name: dist
|
|
51
|
+
path: dist/
|
|
52
|
+
- name: Create GitHub Release
|
|
53
|
+
env:
|
|
54
|
+
GH_TOKEN: ${{ github.token }}
|
|
55
|
+
run: |
|
|
56
|
+
if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then
|
|
57
|
+
echo "Release ${{ github.ref_name }} already exists, uploading assets"
|
|
58
|
+
gh release upload "${{ github.ref_name }}" dist/* --clobber
|
|
59
|
+
else
|
|
60
|
+
gh release create "${{ github.ref_name }}" \
|
|
61
|
+
--title "${{ github.ref_name }}" \
|
|
62
|
+
--generate-notes \
|
|
63
|
+
dist/*
|
|
64
|
+
fi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
unit-tests:
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
16
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
- run: pip install -e ".[dev]"
|
|
23
|
+
- run: ruff check .
|
|
24
|
+
- run: mypy cdpwave/
|
|
25
|
+
- run: pytest tests/unit/ --cov=cdpwave --cov-report=xml --cov-fail-under=80
|
|
26
|
+
- uses: codecov/codecov-action@v4
|
|
27
|
+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
|
|
28
|
+
with:
|
|
29
|
+
files: ./coverage.xml
|
|
30
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
cdpwave-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.eggs/
|
|
8
|
+
*.egg
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
env/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
.coverage
|
|
16
|
+
coverage.xml
|
|
17
|
+
htmlcov/
|
|
18
|
+
*.so
|
|
19
|
+
.idea/
|
|
20
|
+
.vscode/
|
|
21
|
+
*.swp
|
|
22
|
+
*.swo
|
|
23
|
+
site/
|
|
24
|
+
CONTEXT.md
|
|
25
|
+
spike.py
|
cdpwave-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mathias Paulenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cdpwave-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.PHONY: install lint typecheck test test-unit test-integration clean build docs
|
|
2
|
+
|
|
3
|
+
install:
|
|
4
|
+
pip install -e ".[dev]"
|
|
5
|
+
|
|
6
|
+
lint:
|
|
7
|
+
ruff check .
|
|
8
|
+
|
|
9
|
+
typecheck:
|
|
10
|
+
mypy cdpwave/
|
|
11
|
+
|
|
12
|
+
test: test-unit test-integration
|
|
13
|
+
|
|
14
|
+
test-unit:
|
|
15
|
+
pytest tests/unit/ -v --cov=cdpwave --cov-report=term-missing
|
|
16
|
+
|
|
17
|
+
test-integration:
|
|
18
|
+
pytest tests/integration/ -m integration -v
|
|
19
|
+
|
|
20
|
+
clean:
|
|
21
|
+
rm -rf build/ dist/ *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov coverage.xml
|
|
22
|
+
|
|
23
|
+
build:
|
|
24
|
+
python -m build
|
|
25
|
+
|
|
26
|
+
docs:
|
|
27
|
+
mkdocs serve
|
cdpwave-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cdpwave
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Chrome DevTools Protocol for Python — direct CDP over WebSocket, no Selenium, no Playwright
|
|
5
|
+
Project-URL: Homepage, https://github.com/MathiasPaulenko/cdpwave
|
|
6
|
+
Project-URL: Repository, https://github.com/MathiasPaulenko/cdpwave
|
|
7
|
+
Project-URL: Issues, https://github.com/MathiasPaulenko/cdpwave/issues
|
|
8
|
+
Author-email: Mathias Paulenko <mathias.paulenko@outlook.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: async,automation,browser,cdp,chrome,chromium,devtools
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
20
|
+
Classifier: Topic :: Software Development :: Testing
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: pydantic>=2.5
|
|
23
|
+
Requires-Dist: websockets>=12.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
33
|
+
Requires-Dist: mkdocs>=1.6; extra == 'docs'
|
|
34
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# cdpwave
|
|
38
|
+
|
|
39
|
+
[](https://github.com/MathiasPaulenko/cdpwave/actions/workflows/ci.yml)
|
|
40
|
+
[](https://github.com/MathiasPaulenko/cdpwave/actions/workflows/test.yml)
|
|
41
|
+
[](https://pypi.org/project/cdpwave/)
|
|
42
|
+
[](https://pypi.org/project/cdpwave/)
|
|
43
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
|
+
|
|
45
|
+
Chrome DevTools Protocol for Python — direct, typed, async.
|
|
46
|
+
|
|
47
|
+
cdpwave talks to Chrome over a raw WebSocket. No Node.js, no ChromeDriver, no browser downloads. Just pure Python with full type hints and async-first design.
|
|
48
|
+
|
|
49
|
+
## Why cdpwave?
|
|
50
|
+
|
|
51
|
+
- **Direct WebSocket** — single connection to Chrome's DevTools Protocol, no intermediate layers
|
|
52
|
+
- **Fully typed** — `mypy --strict` across the entire codebase, IDE autocomplete everywhere
|
|
53
|
+
- **Async-first** — built on `asyncio`, no threading, no blocking calls
|
|
54
|
+
- **Browser detection** — finds Chrome, Edge, Brave, or Chromium already on your system
|
|
55
|
+
- **Flatten sessions** — one WebSocket for all tabs via `Target.attachToTarget` + `sessionId`
|
|
56
|
+
- **Escape hatch** — `session.send("Any.CDPMethod", params)` for uncovered domains
|
|
57
|
+
- **HTTP discovery** — typed access to `/json/version` and `/json/list` endpoints
|
|
58
|
+
- **MIT licensed** — permissive, compatible with any use
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install cdpwave
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick start
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import asyncio
|
|
70
|
+
from cdpwave import CDPClient
|
|
71
|
+
|
|
72
|
+
async def main() -> None:
|
|
73
|
+
async with await CDPClient.launch(headless=True) as client:
|
|
74
|
+
page = await client.new_page("https://example.com")
|
|
75
|
+
result = await page.runtime.evaluate("document.title", return_by_value=True)
|
|
76
|
+
print(result["result"]["value"]) # "Example Domain"
|
|
77
|
+
await page.close()
|
|
78
|
+
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Documentation
|
|
83
|
+
|
|
84
|
+
Full documentation at [mathiaspaulenko.github.io/cdpwave](https://mathiaspaulenko.github.io/cdpwave/).
|
|
85
|
+
|
|
86
|
+
- [Quickstart](https://mathiaspaulenko.github.io/cdpwave/quickstart/) — 10-minute tutorial
|
|
87
|
+
- [Guide](https://mathiaspaulenko.github.io/cdpwave/guide/installation/) — in-depth feature coverage
|
|
88
|
+
- [Cookbook](https://mathiaspaulenko.github.io/cdpwave/cookbook/connect-existing/) — common recipes
|
|
89
|
+
- [API Reference](https://mathiaspaulenko.github.io/cdpwave/api/client/) — auto-generated docs
|
|
90
|
+
- [Migration](https://mathiaspaulenko.github.io/cdpwave/migration/pyppeteer/) — from pyppeteer or pychrome
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
cdpwave-0.1.0/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# cdpwave
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MathiasPaulenko/cdpwave/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/MathiasPaulenko/cdpwave/actions/workflows/test.yml)
|
|
5
|
+
[](https://pypi.org/project/cdpwave/)
|
|
6
|
+
[](https://pypi.org/project/cdpwave/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
Chrome DevTools Protocol for Python — direct, typed, async.
|
|
10
|
+
|
|
11
|
+
cdpwave talks to Chrome over a raw WebSocket. No Node.js, no ChromeDriver, no browser downloads. Just pure Python with full type hints and async-first design.
|
|
12
|
+
|
|
13
|
+
## Why cdpwave?
|
|
14
|
+
|
|
15
|
+
- **Direct WebSocket** — single connection to Chrome's DevTools Protocol, no intermediate layers
|
|
16
|
+
- **Fully typed** — `mypy --strict` across the entire codebase, IDE autocomplete everywhere
|
|
17
|
+
- **Async-first** — built on `asyncio`, no threading, no blocking calls
|
|
18
|
+
- **Browser detection** — finds Chrome, Edge, Brave, or Chromium already on your system
|
|
19
|
+
- **Flatten sessions** — one WebSocket for all tabs via `Target.attachToTarget` + `sessionId`
|
|
20
|
+
- **Escape hatch** — `session.send("Any.CDPMethod", params)` for uncovered domains
|
|
21
|
+
- **HTTP discovery** — typed access to `/json/version` and `/json/list` endpoints
|
|
22
|
+
- **MIT licensed** — permissive, compatible with any use
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install cdpwave
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import asyncio
|
|
34
|
+
from cdpwave import CDPClient
|
|
35
|
+
|
|
36
|
+
async def main() -> None:
|
|
37
|
+
async with await CDPClient.launch(headless=True) as client:
|
|
38
|
+
page = await client.new_page("https://example.com")
|
|
39
|
+
result = await page.runtime.evaluate("document.title", return_by_value=True)
|
|
40
|
+
print(result["result"]["value"]) # "Example Domain"
|
|
41
|
+
await page.close()
|
|
42
|
+
|
|
43
|
+
asyncio.run(main())
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
Full documentation at [mathiaspaulenko.github.io/cdpwave](https://mathiaspaulenko.github.io/cdpwave/).
|
|
49
|
+
|
|
50
|
+
- [Quickstart](https://mathiaspaulenko.github.io/cdpwave/quickstart/) — 10-minute tutorial
|
|
51
|
+
- [Guide](https://mathiaspaulenko.github.io/cdpwave/guide/installation/) — in-depth feature coverage
|
|
52
|
+
- [Cookbook](https://mathiaspaulenko.github.io/cdpwave/cookbook/connect-existing/) — common recipes
|
|
53
|
+
- [API Reference](https://mathiaspaulenko.github.io/cdpwave/api/client/) — auto-generated docs
|
|
54
|
+
- [Migration](https://mathiaspaulenko.github.io/cdpwave/migration/pyppeteer/) — from pyppeteer or pychrome
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
2
|
+
|
|
3
|
+
from cdpwave.client import CDPClient, CDPSession
|
|
4
|
+
from cdpwave.events.dispatcher import EventDispatcher
|
|
5
|
+
from cdpwave.events.handlers import EventHandler, Subscription
|
|
6
|
+
from cdpwave.exceptions import (
|
|
7
|
+
BrowserNotFoundError,
|
|
8
|
+
CDPError,
|
|
9
|
+
CommandError,
|
|
10
|
+
CommandTimeoutError,
|
|
11
|
+
ConnectionClosedError,
|
|
12
|
+
DiscoveryError,
|
|
13
|
+
LaunchError,
|
|
14
|
+
LaunchTimeoutError,
|
|
15
|
+
SessionClosedError,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"CDPClient",
|
|
20
|
+
"CDPSession",
|
|
21
|
+
"CDPError",
|
|
22
|
+
"ConnectionClosedError",
|
|
23
|
+
"CommandError",
|
|
24
|
+
"CommandTimeoutError",
|
|
25
|
+
"BrowserNotFoundError",
|
|
26
|
+
"SessionClosedError",
|
|
27
|
+
"DiscoveryError",
|
|
28
|
+
"EventDispatcher",
|
|
29
|
+
"Subscription",
|
|
30
|
+
"EventHandler",
|
|
31
|
+
"LaunchError",
|
|
32
|
+
"LaunchTimeoutError",
|
|
33
|
+
"__version__",
|
|
34
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
import urllib.request
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class TargetInfo:
|
|
10
|
+
target_id: str
|
|
11
|
+
type: str
|
|
12
|
+
title: str
|
|
13
|
+
url: str
|
|
14
|
+
web_socket_debugger_url: str | None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class VersionInfo:
|
|
19
|
+
browser: str
|
|
20
|
+
protocol_version: str
|
|
21
|
+
user_agent: str
|
|
22
|
+
web_socket_debugger_url: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _http_get(url: str) -> Any:
|
|
26
|
+
with urllib.request.urlopen(url, timeout=10) as resp:
|
|
27
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
28
|
+
return data
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _http_put(url: str) -> Any:
|
|
32
|
+
req = urllib.request.Request(url, method="PUT")
|
|
33
|
+
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
34
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
35
|
+
return data
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TargetDiscovery:
|
|
39
|
+
def __init__(self, host: str = "localhost", port: int = 9222) -> None:
|
|
40
|
+
self._base_url = f"http://{host}:{port}"
|
|
41
|
+
|
|
42
|
+
async def get_version(self) -> VersionInfo:
|
|
43
|
+
data: dict[str, Any] = await asyncio.to_thread(
|
|
44
|
+
_http_get, f"{self._base_url}/json/version"
|
|
45
|
+
)
|
|
46
|
+
return VersionInfo(
|
|
47
|
+
browser=str(data.get("Browser", "")),
|
|
48
|
+
protocol_version=str(data.get("Protocol-Version", "")),
|
|
49
|
+
user_agent=str(data.get("User-Agent", "")),
|
|
50
|
+
web_socket_debugger_url=str(data.get("webSocketDebuggerUrl", "")),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
async def list_targets(self) -> list[TargetInfo]:
|
|
54
|
+
data: list[dict[str, Any]] = await asyncio.to_thread(
|
|
55
|
+
_http_get, f"{self._base_url}/json/list"
|
|
56
|
+
)
|
|
57
|
+
targets: list[TargetInfo] = []
|
|
58
|
+
for item in data:
|
|
59
|
+
targets.append(
|
|
60
|
+
TargetInfo(
|
|
61
|
+
target_id=str(item.get("id", "")),
|
|
62
|
+
type=str(item.get("type", "")),
|
|
63
|
+
title=str(item.get("title", "")),
|
|
64
|
+
url=str(item.get("url", "")),
|
|
65
|
+
web_socket_debugger_url=item.get("webSocketDebuggerUrl"),
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
return targets
|
|
69
|
+
|
|
70
|
+
async def new_tab(self, url: str = "about:blank") -> TargetInfo:
|
|
71
|
+
data: dict[str, Any] = await asyncio.to_thread(
|
|
72
|
+
_http_put, f"{self._base_url}/json/new?{url}"
|
|
73
|
+
)
|
|
74
|
+
return TargetInfo(
|
|
75
|
+
target_id=str(data.get("id", "")),
|
|
76
|
+
type=str(data.get("type", "")),
|
|
77
|
+
title=str(data.get("title", "")),
|
|
78
|
+
url=str(data.get("url", "")),
|
|
79
|
+
web_socket_debugger_url=data.get("webSocketDebuggerUrl"),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
async def activate_tab(self, target_id: str) -> None:
|
|
83
|
+
await asyncio.to_thread(_http_get, f"{self._base_url}/json/activate/{target_id}")
|
|
84
|
+
|
|
85
|
+
async def close_tab(self, target_id: str) -> None:
|
|
86
|
+
await asyncio.to_thread(_http_get, f"{self._base_url}/json/close/{target_id}")
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from cdpwave.exceptions import BrowserNotFoundError
|
|
6
|
+
from cdpwave.types import BrowserType
|
|
7
|
+
|
|
8
|
+
_WIN_CHROME_PATHS = [
|
|
9
|
+
r"C:\Program Files\Google\Chrome\Application\chrome.exe",
|
|
10
|
+
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
_WIN_EDGE_PATHS = [
|
|
14
|
+
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
|
|
15
|
+
r"C:\Program Files\Microsoft\Edge\Application\msedge.exe",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
_WIN_BRAVE_PATHS = [
|
|
19
|
+
os.path.expandvars(r"%LOCALAPPDATA%\BraveSoftware\Brave-Browser\Application\brave.exe"),
|
|
20
|
+
r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe",
|
|
21
|
+
r"C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
_WIN_CHROMIUM_PATHS = [
|
|
25
|
+
r"C:\Program Files\Chromium\Application\chromium.exe",
|
|
26
|
+
r"C:\Program Files (x86)\Chromium\Application\chromium.exe",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
_MAC_CHROME_PATH = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
|
30
|
+
_MAC_EDGE_PATH = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
|
|
31
|
+
_MAC_BRAVE_PATH = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
|
|
32
|
+
_MAC_CHROMIUM_PATH = "/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
33
|
+
|
|
34
|
+
_LINUX_NAMES: dict[str, list[str]] = {
|
|
35
|
+
"chrome": ["google-chrome", "google-chrome-stable", "chrome"],
|
|
36
|
+
"edge": ["microsoft-edge", "microsoft-edge-stable"],
|
|
37
|
+
"brave": ["brave-browser", "brave"],
|
|
38
|
+
"chromium": ["chromium", "chromium-browser"],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _check_paths(paths: list[str]) -> str | None:
|
|
43
|
+
for path in paths:
|
|
44
|
+
if os.path.isfile(path):
|
|
45
|
+
return path
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _find_on_linux(names: list[str]) -> str | None:
|
|
50
|
+
for name in names:
|
|
51
|
+
path = shutil.which(name)
|
|
52
|
+
if path:
|
|
53
|
+
return path
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def find_chrome() -> str | None:
|
|
58
|
+
env_path = os.environ.get("CDPWAVE_CHROME_PATH")
|
|
59
|
+
if env_path and os.path.isfile(env_path):
|
|
60
|
+
return env_path
|
|
61
|
+
if sys.platform == "win32":
|
|
62
|
+
return _check_paths(_WIN_CHROME_PATHS)
|
|
63
|
+
if sys.platform == "darwin":
|
|
64
|
+
return _check_paths([_MAC_CHROME_PATH])
|
|
65
|
+
return _find_on_linux(_LINUX_NAMES["chrome"])
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def find_edge() -> str | None:
|
|
69
|
+
env_path = os.environ.get("CDPWAVE_EDGE_PATH")
|
|
70
|
+
if env_path and os.path.isfile(env_path):
|
|
71
|
+
return env_path
|
|
72
|
+
if sys.platform == "win32":
|
|
73
|
+
return _check_paths(_WIN_EDGE_PATHS)
|
|
74
|
+
if sys.platform == "darwin":
|
|
75
|
+
return _check_paths([_MAC_EDGE_PATH])
|
|
76
|
+
return _find_on_linux(_LINUX_NAMES["edge"])
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def find_brave() -> str | None:
|
|
80
|
+
env_path = os.environ.get("CDPWAVE_BRAVE_PATH")
|
|
81
|
+
if env_path and os.path.isfile(env_path):
|
|
82
|
+
return env_path
|
|
83
|
+
if sys.platform == "win32":
|
|
84
|
+
return _check_paths(_WIN_BRAVE_PATHS)
|
|
85
|
+
if sys.platform == "darwin":
|
|
86
|
+
return _check_paths([_MAC_BRAVE_PATH])
|
|
87
|
+
return _find_on_linux(_LINUX_NAMES["brave"])
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def find_chromium() -> str | None:
|
|
91
|
+
env_path = os.environ.get("CDPWAVE_CHROMIUM_PATH")
|
|
92
|
+
if env_path and os.path.isfile(env_path):
|
|
93
|
+
return env_path
|
|
94
|
+
if sys.platform == "win32":
|
|
95
|
+
return _check_paths(_WIN_CHROMIUM_PATHS)
|
|
96
|
+
if sys.platform == "darwin":
|
|
97
|
+
return _check_paths([_MAC_CHROMIUM_PATH])
|
|
98
|
+
return _find_on_linux(_LINUX_NAMES["chromium"])
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
_FINDER_NAMES: dict[BrowserType, str] = {
|
|
102
|
+
"chrome": "find_chrome",
|
|
103
|
+
"edge": "find_edge",
|
|
104
|
+
"brave": "find_brave",
|
|
105
|
+
"chromium": "find_chromium",
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_SEARCH_ORDER: list[BrowserType] = ["chrome", "edge", "brave", "chromium"]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def find_browser(preferred: BrowserType | None = None) -> str:
|
|
112
|
+
env_override = os.environ.get("CDPWAVE_BROWSER_PATH")
|
|
113
|
+
if env_override and os.path.isfile(env_override):
|
|
114
|
+
return env_override
|
|
115
|
+
|
|
116
|
+
search_order: list[BrowserType] = []
|
|
117
|
+
if preferred is not None:
|
|
118
|
+
search_order.append(preferred)
|
|
119
|
+
search_order.extend([b for b in _SEARCH_ORDER if b != preferred])
|
|
120
|
+
|
|
121
|
+
for browser_type in search_order:
|
|
122
|
+
finder = globals()[_FINDER_NAMES[browser_type]]
|
|
123
|
+
path: str | None = finder()
|
|
124
|
+
if path:
|
|
125
|
+
return path
|
|
126
|
+
|
|
127
|
+
raise BrowserNotFoundError(
|
|
128
|
+
"No Chromium-based browser found."
|
|
129
|
+
" Set CDPWAVE_BROWSER_PATH or install Chrome/Edge/Brave/Chromium."
|
|
130
|
+
)
|