chromedeveloperprotocol-client 0.1.0__py3-none-any.whl
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.
- cdp/__init__.py +4 -0
- cdp/domains.py +582 -0
- cdp/generator/__init__.py +3 -0
- cdp/generator/client_generator.py +246 -0
- cdp/generator/constant.py +4 -0
- cdp/generator/domain_generator.py +149 -0
- cdp/generator/event_generator.py +202 -0
- cdp/generator/method_generator.py +215 -0
- cdp/generator/service.py +153 -0
- cdp/generator/type_generator.py +231 -0
- cdp/protocol/__init__.py +0 -0
- cdp/protocol/accessibility/__init__.py +0 -0
- cdp/protocol/accessibility/events/__init__.py +0 -0
- cdp/protocol/accessibility/events/service.py +37 -0
- cdp/protocol/accessibility/events/types.py +14 -0
- cdp/protocol/accessibility/methods/__init__.py +0 -0
- cdp/protocol/accessibility/methods/service.py +109 -0
- cdp/protocol/accessibility/methods/types.py +70 -0
- cdp/protocol/accessibility/service.py +21 -0
- cdp/protocol/accessibility/types.py +89 -0
- cdp/protocol/animation/__init__.py +0 -0
- cdp/protocol/animation/events/__init__.py +0 -0
- cdp/protocol/animation/events/service.py +53 -0
- cdp/protocol/animation/events/types.py +20 -0
- cdp/protocol/animation/methods/__init__.py +0 -0
- cdp/protocol/animation/methods/service.py +131 -0
- cdp/protocol/animation/methods/types.py +52 -0
- cdp/protocol/animation/service.py +21 -0
- cdp/protocol/animation/types.py +79 -0
- cdp/protocol/audits/__init__.py +0 -0
- cdp/protocol/audits/events/__init__.py +0 -0
- cdp/protocol/audits/events/service.py +29 -0
- cdp/protocol/audits/events/types.py +10 -0
- cdp/protocol/audits/methods/__init__.py +0 -0
- cdp/protocol/audits/methods/service.py +76 -0
- cdp/protocol/audits/methods/types.py +36 -0
- cdp/protocol/audits/service.py +21 -0
- cdp/protocol/audits/types.py +293 -0
- cdp/protocol/autofill/__init__.py +0 -0
- cdp/protocol/autofill/events/__init__.py +0 -0
- cdp/protocol/autofill/events/service.py +29 -0
- cdp/protocol/autofill/events/types.py +14 -0
- cdp/protocol/autofill/methods/__init__.py +0 -0
- cdp/protocol/autofill/methods/service.py +65 -0
- cdp/protocol/autofill/methods/types.py +22 -0
- cdp/protocol/autofill/service.py +21 -0
- cdp/protocol/autofill/types.py +54 -0
- cdp/protocol/background_service/__init__.py +0 -0
- cdp/protocol/background_service/events/__init__.py +0 -0
- cdp/protocol/background_service/events/service.py +37 -0
- cdp/protocol/background_service/events/types.py +14 -0
- cdp/protocol/background_service/methods/__init__.py +0 -0
- cdp/protocol/background_service/methods/service.py +65 -0
- cdp/protocol/background_service/methods/types.py +17 -0
- cdp/protocol/background_service/service.py +21 -0
- cdp/protocol/background_service/types.py +32 -0
- cdp/protocol/bluetooth_emulation/__init__.py +0 -0
- cdp/protocol/bluetooth_emulation/events/__init__.py +0 -0
- cdp/protocol/bluetooth_emulation/events/service.py +45 -0
- cdp/protocol/bluetooth_emulation/events/types.py +23 -0
- cdp/protocol/bluetooth_emulation/methods/__init__.py +0 -0
- cdp/protocol/bluetooth_emulation/methods/service.py +186 -0
- cdp/protocol/bluetooth_emulation/methods/types.py +81 -0
- cdp/protocol/bluetooth_emulation/service.py +21 -0
- cdp/protocol/bluetooth_emulation/types.py +45 -0
- cdp/protocol/browser/__init__.py +0 -0
- cdp/protocol/browser/events/__init__.py +0 -0
- cdp/protocol/browser/events/service.py +37 -0
- cdp/protocol/browser/events/types.py +28 -0
- cdp/protocol/browser/methods/__init__.py +0 -0
- cdp/protocol/browser/methods/service.py +230 -0
- cdp/protocol/browser/methods/types.py +126 -0
- cdp/protocol/browser/service.py +21 -0
- cdp/protocol/browser/types.py +57 -0
- cdp/protocol/cache_storage/__init__.py +0 -0
- cdp/protocol/cache_storage/events/__init__.py +0 -0
- cdp/protocol/cache_storage/events/service.py +20 -0
- cdp/protocol/cache_storage/events/types.py +3 -0
- cdp/protocol/cache_storage/methods/__init__.py +0 -0
- cdp/protocol/cache_storage/methods/service.py +76 -0
- cdp/protocol/cache_storage/methods/types.py +57 -0
- cdp/protocol/cache_storage/service.py +21 -0
- cdp/protocol/cache_storage/types.py +49 -0
- cdp/protocol/cast/__init__.py +0 -0
- cdp/protocol/cast/events/__init__.py +0 -0
- cdp/protocol/cast/events/service.py +37 -0
- cdp/protocol/cast/events/types.py +12 -0
- cdp/protocol/cast/methods/__init__.py +0 -0
- cdp/protocol/cast/methods/service.py +87 -0
- cdp/protocol/cast/methods/types.py +15 -0
- cdp/protocol/cast/service.py +21 -0
- cdp/protocol/cast/types.py +9 -0
- cdp/protocol/css/__init__.py +0 -0
- cdp/protocol/css/events/__init__.py +0 -0
- cdp/protocol/css/events/service.py +69 -0
- cdp/protocol/css/events/types.py +27 -0
- cdp/protocol/css/methods/__init__.py +0 -0
- cdp/protocol/css/methods/service.py +428 -0
- cdp/protocol/css/methods/types.py +278 -0
- cdp/protocol/css/service.py +21 -0
- cdp/protocol/css/types.py +451 -0
- cdp/protocol/debugger/__init__.py +0 -0
- cdp/protocol/debugger/events/__init__.py +0 -0
- cdp/protocol/debugger/events/service.py +53 -0
- cdp/protocol/debugger/events/types.py +112 -0
- cdp/protocol/debugger/methods/__init__.py +0 -0
- cdp/protocol/debugger/methods/service.py +362 -0
- cdp/protocol/debugger/methods/types.py +250 -0
- cdp/protocol/debugger/service.py +21 -0
- cdp/protocol/debugger/types.py +91 -0
- cdp/protocol/device_access/__init__.py +0 -0
- cdp/protocol/device_access/events/__init__.py +0 -0
- cdp/protocol/device_access/events/service.py +29 -0
- cdp/protocol/device_access/events/types.py +12 -0
- cdp/protocol/device_access/methods/__init__.py +0 -0
- cdp/protocol/device_access/methods/service.py +65 -0
- cdp/protocol/device_access/methods/types.py +16 -0
- cdp/protocol/device_access/service.py +21 -0
- cdp/protocol/device_access/types.py +13 -0
- cdp/protocol/device_orientation/__init__.py +0 -0
- cdp/protocol/device_orientation/events/__init__.py +0 -0
- cdp/protocol/device_orientation/events/service.py +20 -0
- cdp/protocol/device_orientation/events/types.py +3 -0
- cdp/protocol/device_orientation/methods/__init__.py +0 -0
- cdp/protocol/device_orientation/methods/service.py +43 -0
- cdp/protocol/device_orientation/methods/types.py +12 -0
- cdp/protocol/device_orientation/service.py +21 -0
- cdp/protocol/device_orientation/types.py +3 -0
- cdp/protocol/dom/__init__.py +0 -0
- cdp/protocol/dom/events/__init__.py +0 -0
- cdp/protocol/dom/events/service.py +165 -0
- cdp/protocol/dom/events/types.py +97 -0
- cdp/protocol/dom/methods/__init__.py +0 -0
- cdp/protocol/dom/methods/service.py +593 -0
- cdp/protocol/dom/methods/types.py +384 -0
- cdp/protocol/dom/service.py +21 -0
- cdp/protocol/dom/types.py +151 -0
- cdp/protocol/dom_debugger/__init__.py +0 -0
- cdp/protocol/dom_debugger/events/__init__.py +0 -0
- cdp/protocol/dom_debugger/events/service.py +20 -0
- cdp/protocol/dom_debugger/events/types.py +3 -0
- cdp/protocol/dom_debugger/methods/__init__.py +0 -0
- cdp/protocol/dom_debugger/methods/service.py +109 -0
- cdp/protocol/dom_debugger/methods/types.py +51 -0
- cdp/protocol/dom_debugger/service.py +21 -0
- cdp/protocol/dom_debugger/types.py +36 -0
- cdp/protocol/dom_snapshot/__init__.py +0 -0
- cdp/protocol/dom_snapshot/events/__init__.py +0 -0
- cdp/protocol/dom_snapshot/events/service.py +20 -0
- cdp/protocol/dom_snapshot/events/types.py +3 -0
- cdp/protocol/dom_snapshot/methods/__init__.py +0 -0
- cdp/protocol/dom_snapshot/methods/service.py +54 -0
- cdp/protocol/dom_snapshot/methods/types.py +28 -0
- cdp/protocol/dom_snapshot/service.py +21 -0
- cdp/protocol/dom_snapshot/types.py +220 -0
- cdp/protocol/dom_storage/__init__.py +0 -0
- cdp/protocol/dom_storage/events/__init__.py +0 -0
- cdp/protocol/dom_storage/events/service.py +53 -0
- cdp/protocol/dom_storage/events/types.py +22 -0
- cdp/protocol/dom_storage/methods/__init__.py +0 -0
- cdp/protocol/dom_storage/methods/service.py +87 -0
- cdp/protocol/dom_storage/methods/types.py +27 -0
- cdp/protocol/dom_storage/service.py +21 -0
- cdp/protocol/dom_storage/types.py +15 -0
- cdp/protocol/emulation/__init__.py +0 -0
- cdp/protocol/emulation/events/__init__.py +0 -0
- cdp/protocol/emulation/events/service.py +29 -0
- cdp/protocol/emulation/events/types.py +6 -0
- cdp/protocol/emulation/methods/__init__.py +0 -0
- cdp/protocol/emulation/methods/service.py +494 -0
- cdp/protocol/emulation/methods/types.py +261 -0
- cdp/protocol/emulation/service.py +21 -0
- cdp/protocol/emulation/types.py +132 -0
- cdp/protocol/event_breakpoints/__init__.py +0 -0
- cdp/protocol/event_breakpoints/events/__init__.py +0 -0
- cdp/protocol/event_breakpoints/events/service.py +20 -0
- cdp/protocol/event_breakpoints/events/types.py +3 -0
- cdp/protocol/event_breakpoints/methods/__init__.py +0 -0
- cdp/protocol/event_breakpoints/methods/service.py +54 -0
- cdp/protocol/event_breakpoints/methods/types.py +10 -0
- cdp/protocol/event_breakpoints/service.py +21 -0
- cdp/protocol/event_breakpoints/types.py +3 -0
- cdp/protocol/extensions/__init__.py +0 -0
- cdp/protocol/extensions/events/__init__.py +0 -0
- cdp/protocol/extensions/events/service.py +20 -0
- cdp/protocol/extensions/events/types.py +3 -0
- cdp/protocol/extensions/methods/__init__.py +0 -0
- cdp/protocol/extensions/methods/service.py +87 -0
- cdp/protocol/extensions/methods/types.py +46 -0
- cdp/protocol/extensions/service.py +21 -0
- cdp/protocol/extensions/types.py +6 -0
- cdp/protocol/fed_cm/__init__.py +0 -0
- cdp/protocol/fed_cm/events/__init__.py +0 -0
- cdp/protocol/fed_cm/events/service.py +37 -0
- cdp/protocol/fed_cm/events/types.py +18 -0
- cdp/protocol/fed_cm/methods/__init__.py +0 -0
- cdp/protocol/fed_cm/methods/service.py +98 -0
- cdp/protocol/fed_cm/methods/types.py +26 -0
- cdp/protocol/fed_cm/service.py +21 -0
- cdp/protocol/fed_cm/types.py +25 -0
- cdp/protocol/fetch/__init__.py +0 -0
- cdp/protocol/fetch/events/__init__.py +0 -0
- cdp/protocol/fetch/events/service.py +37 -0
- cdp/protocol/fetch/events/types.py +47 -0
- cdp/protocol/fetch/methods/__init__.py +0 -0
- cdp/protocol/fetch/methods/service.py +120 -0
- cdp/protocol/fetch/methods/types.py +85 -0
- cdp/protocol/fetch/service.py +21 -0
- cdp/protocol/fetch/types.py +41 -0
- cdp/protocol/file_system/__init__.py +0 -0
- cdp/protocol/file_system/events/__init__.py +0 -0
- cdp/protocol/file_system/events/service.py +20 -0
- cdp/protocol/file_system/events/types.py +3 -0
- cdp/protocol/file_system/methods/__init__.py +0 -0
- cdp/protocol/file_system/methods/service.py +32 -0
- cdp/protocol/file_system/methods/types.py +14 -0
- cdp/protocol/file_system/service.py +21 -0
- cdp/protocol/file_system/types.py +28 -0
- cdp/protocol/headless_experimental/__init__.py +0 -0
- cdp/protocol/headless_experimental/events/__init__.py +0 -0
- cdp/protocol/headless_experimental/events/service.py +20 -0
- cdp/protocol/headless_experimental/events/types.py +3 -0
- cdp/protocol/headless_experimental/methods/__init__.py +0 -0
- cdp/protocol/headless_experimental/methods/service.py +32 -0
- cdp/protocol/headless_experimental/methods/types.py +22 -0
- cdp/protocol/headless_experimental/service.py +21 -0
- cdp/protocol/headless_experimental/types.py +12 -0
- cdp/protocol/heap_profiler/__init__.py +0 -0
- cdp/protocol/heap_profiler/events/__init__.py +0 -0
- cdp/protocol/heap_profiler/events/service.py +61 -0
- cdp/protocol/heap_profiler/events/types.py +18 -0
- cdp/protocol/heap_profiler/methods/__init__.py +0 -0
- cdp/protocol/heap_profiler/methods/service.py +153 -0
- cdp/protocol/heap_profiler/methods/types.py +73 -0
- cdp/protocol/heap_profiler/service.py +21 -0
- cdp/protocol/heap_profiler/types.py +32 -0
- cdp/protocol/indexed_db/__init__.py +0 -0
- cdp/protocol/indexed_db/events/__init__.py +0 -0
- cdp/protocol/indexed_db/events/service.py +20 -0
- cdp/protocol/indexed_db/events/types.py +3 -0
- cdp/protocol/indexed_db/methods/__init__.py +0 -0
- cdp/protocol/indexed_db/methods/service.py +120 -0
- cdp/protocol/indexed_db/methods/types.py +111 -0
- cdp/protocol/indexed_db/service.py +21 -0
- cdp/protocol/indexed_db/types.py +74 -0
- cdp/protocol/input/__init__.py +0 -0
- cdp/protocol/input/events/__init__.py +0 -0
- cdp/protocol/input/events/service.py +29 -0
- cdp/protocol/input/events/types.py +10 -0
- cdp/protocol/input/methods/__init__.py +0 -0
- cdp/protocol/input/methods/service.py +164 -0
- cdp/protocol/input/methods/types.py +181 -0
- cdp/protocol/input/service.py +21 -0
- cdp/protocol/input/types.py +46 -0
- cdp/protocol/inspector/__init__.py +0 -0
- cdp/protocol/inspector/events/__init__.py +0 -0
- cdp/protocol/inspector/events/service.py +53 -0
- cdp/protocol/inspector/events/types.py +13 -0
- cdp/protocol/inspector/methods/__init__.py +0 -0
- cdp/protocol/inspector/methods/service.py +43 -0
- cdp/protocol/inspector/methods/types.py +3 -0
- cdp/protocol/inspector/service.py +21 -0
- cdp/protocol/inspector/types.py +3 -0
- cdp/protocol/io/__init__.py +0 -0
- cdp/protocol/io/events/__init__.py +0 -0
- cdp/protocol/io/events/service.py +20 -0
- cdp/protocol/io/events/types.py +3 -0
- cdp/protocol/io/methods/__init__.py +0 -0
- cdp/protocol/io/methods/service.py +54 -0
- cdp/protocol/io/methods/types.py +33 -0
- cdp/protocol/io/service.py +21 -0
- cdp/protocol/io/types.py +6 -0
- cdp/protocol/layer_tree/__init__.py +0 -0
- cdp/protocol/layer_tree/events/__init__.py +0 -0
- cdp/protocol/layer_tree/events/service.py +37 -0
- cdp/protocol/layer_tree/events/types.py +18 -0
- cdp/protocol/layer_tree/methods/__init__.py +0 -0
- cdp/protocol/layer_tree/methods/service.py +120 -0
- cdp/protocol/layer_tree/methods/types.py +70 -0
- cdp/protocol/layer_tree/service.py +21 -0
- cdp/protocol/layer_tree/types.py +73 -0
- cdp/protocol/log/__init__.py +0 -0
- cdp/protocol/log/events/__init__.py +0 -0
- cdp/protocol/log/events/service.py +29 -0
- cdp/protocol/log/events/types.py +11 -0
- cdp/protocol/log/methods/__init__.py +0 -0
- cdp/protocol/log/methods/service.py +76 -0
- cdp/protocol/log/methods/types.py +14 -0
- cdp/protocol/log/service.py +21 -0
- cdp/protocol/log/types.py +40 -0
- cdp/protocol/media/__init__.py +0 -0
- cdp/protocol/media/events/__init__.py +0 -0
- cdp/protocol/media/events/service.py +61 -0
- cdp/protocol/media/events/types.py +27 -0
- cdp/protocol/media/methods/__init__.py +0 -0
- cdp/protocol/media/methods/service.py +43 -0
- cdp/protocol/media/methods/types.py +3 -0
- cdp/protocol/media/service.py +21 -0
- cdp/protocol/media/types.py +42 -0
- cdp/protocol/memory/__init__.py +0 -0
- cdp/protocol/memory/events/__init__.py +0 -0
- cdp/protocol/memory/events/service.py +20 -0
- cdp/protocol/memory/events/types.py +3 -0
- cdp/protocol/memory/methods/__init__.py +0 -0
- cdp/protocol/memory/methods/service.py +142 -0
- cdp/protocol/memory/methods/types.py +48 -0
- cdp/protocol/memory/service.py +21 -0
- cdp/protocol/memory/types.py +34 -0
- cdp/protocol/network/__init__.py +0 -0
- cdp/protocol/network/events/__init__.py +0 -0
- cdp/protocol/network/events/service.py +365 -0
- cdp/protocol/network/events/types.py +360 -0
- cdp/protocol/network/methods/__init__.py +0 -0
- cdp/protocol/network/methods/service.py +384 -0
- cdp/protocol/network/methods/types.py +252 -0
- cdp/protocol/network/service.py +21 -0
- cdp/protocol/network/types.py +691 -0
- cdp/protocol/overlay/__init__.py +0 -0
- cdp/protocol/overlay/events/__init__.py +0 -0
- cdp/protocol/overlay/events/service.py +53 -0
- cdp/protocol/overlay/events/types.py +20 -0
- cdp/protocol/overlay/methods/__init__.py +0 -0
- cdp/protocol/overlay/methods/service.py +307 -0
- cdp/protocol/overlay/methods/types.py +144 -0
- cdp/protocol/overlay/service.py +21 -0
- cdp/protocol/overlay/types.py +198 -0
- cdp/protocol/page/__init__.py +0 -0
- cdp/protocol/page/events/__init__.py +0 -0
- cdp/protocol/page/events/service.py +213 -0
- cdp/protocol/page/events/types.py +147 -0
- cdp/protocol/page/methods/__init__.py +0 -0
- cdp/protocol/page/methods/service.py +560 -0
- cdp/protocol/page/methods/types.py +346 -0
- cdp/protocol/page/service.py +21 -0
- cdp/protocol/page/types.py +379 -0
- cdp/protocol/performance/__init__.py +0 -0
- cdp/protocol/performance/events/__init__.py +0 -0
- cdp/protocol/performance/events/service.py +29 -0
- cdp/protocol/performance/events/types.py +13 -0
- cdp/protocol/performance/methods/__init__.py +0 -0
- cdp/protocol/performance/methods/service.py +54 -0
- cdp/protocol/performance/methods/types.py +18 -0
- cdp/protocol/performance/service.py +21 -0
- cdp/protocol/performance/types.py +10 -0
- cdp/protocol/performance_timeline/__init__.py +0 -0
- cdp/protocol/performance_timeline/events/__init__.py +0 -0
- cdp/protocol/performance_timeline/events/service.py +29 -0
- cdp/protocol/performance_timeline/events/types.py +10 -0
- cdp/protocol/performance_timeline/methods/__init__.py +0 -0
- cdp/protocol/performance_timeline/methods/service.py +32 -0
- cdp/protocol/performance_timeline/methods/types.py +7 -0
- cdp/protocol/performance_timeline/service.py +21 -0
- cdp/protocol/performance_timeline/types.py +46 -0
- cdp/protocol/preload/__init__.py +0 -0
- cdp/protocol/preload/events/__init__.py +0 -0
- cdp/protocol/preload/events/service.py +69 -0
- cdp/protocol/preload/events/types.py +49 -0
- cdp/protocol/preload/methods/__init__.py +0 -0
- cdp/protocol/preload/methods/service.py +43 -0
- cdp/protocol/preload/methods/types.py +3 -0
- cdp/protocol/preload/service.py +21 -0
- cdp/protocol/preload/types.py +56 -0
- cdp/protocol/profiler/__init__.py +0 -0
- cdp/protocol/profiler/events/__init__.py +0 -0
- cdp/protocol/profiler/events/service.py +45 -0
- cdp/protocol/profiler/events/types.py +30 -0
- cdp/protocol/profiler/methods/__init__.py +0 -0
- cdp/protocol/profiler/methods/service.py +120 -0
- cdp/protocol/profiler/methods/types.py +45 -0
- cdp/protocol/profiler/service.py +21 -0
- cdp/protocol/profiler/types.py +65 -0
- cdp/protocol/pwa/__init__.py +0 -0
- cdp/protocol/pwa/events/__init__.py +0 -0
- cdp/protocol/pwa/events/service.py +20 -0
- cdp/protocol/pwa/events/types.py +3 -0
- cdp/protocol/pwa/methods/__init__.py +0 -0
- cdp/protocol/pwa/methods/service.py +98 -0
- cdp/protocol/pwa/methods/types.py +43 -0
- cdp/protocol/pwa/service.py +21 -0
- cdp/protocol/pwa/types.py +15 -0
- cdp/protocol/py.typed +0 -0
- cdp/protocol/runtime/__init__.py +0 -0
- cdp/protocol/runtime/events/__init__.py +0 -0
- cdp/protocol/runtime/events/service.py +85 -0
- cdp/protocol/runtime/events/types.py +55 -0
- cdp/protocol/runtime/methods/__init__.py +0 -0
- cdp/protocol/runtime/methods/service.py +274 -0
- cdp/protocol/runtime/methods/types.py +226 -0
- cdp/protocol/runtime/service.py +21 -0
- cdp/protocol/runtime/types.py +194 -0
- cdp/protocol/security/__init__.py +0 -0
- cdp/protocol/security/events/__init__.py +0 -0
- cdp/protocol/security/events/service.py +29 -0
- cdp/protocol/security/events/types.py +11 -0
- cdp/protocol/security/methods/__init__.py +0 -0
- cdp/protocol/security/methods/service.py +54 -0
- cdp/protocol/security/methods/types.py +9 -0
- cdp/protocol/security/service.py +21 -0
- cdp/protocol/security/types.py +102 -0
- cdp/protocol/service_worker/__init__.py +0 -0
- cdp/protocol/service_worker/events/__init__.py +0 -0
- cdp/protocol/service_worker/events/service.py +45 -0
- cdp/protocol/service_worker/events/types.py +16 -0
- cdp/protocol/service_worker/methods/__init__.py +0 -0
- cdp/protocol/service_worker/methods/service.py +153 -0
- cdp/protocol/service_worker/methods/types.py +36 -0
- cdp/protocol/service_worker/service.py +21 -0
- cdp/protocol/service_worker/types.py +38 -0
- cdp/protocol/storage/__init__.py +0 -0
- cdp/protocol/storage/events/__init__.py +0 -0
- cdp/protocol/storage/events/service.py +141 -0
- cdp/protocol/storage/events/types.py +139 -0
- cdp/protocol/storage/methods/__init__.py +0 -0
- cdp/protocol/storage/methods/service.py +428 -0
- cdp/protocol/storage/methods/types.py +184 -0
- cdp/protocol/storage/service.py +21 -0
- cdp/protocol/storage/types.py +236 -0
- cdp/protocol/system_info/__init__.py +0 -0
- cdp/protocol/system_info/events/__init__.py +0 -0
- cdp/protocol/system_info/events/service.py +20 -0
- cdp/protocol/system_info/events/types.py +3 -0
- cdp/protocol/system_info/methods/__init__.py +0 -0
- cdp/protocol/system_info/methods/service.py +54 -0
- cdp/protocol/system_info/methods/types.py +27 -0
- cdp/protocol/system_info/service.py +21 -0
- cdp/protocol/system_info/types.py +71 -0
- cdp/protocol/target/__init__.py +0 -0
- cdp/protocol/target/events/__init__.py +0 -0
- cdp/protocol/target/events/service.py +77 -0
- cdp/protocol/target/events/types.py +38 -0
- cdp/protocol/target/methods/__init__.py +0 -0
- cdp/protocol/target/methods/service.py +219 -0
- cdp/protocol/target/methods/types.py +148 -0
- cdp/protocol/target/service.py +21 -0
- cdp/protocol/target/types.py +44 -0
- cdp/protocol/tethering/__init__.py +0 -0
- cdp/protocol/tethering/events/__init__.py +0 -0
- cdp/protocol/tethering/events/service.py +29 -0
- cdp/protocol/tethering/events/types.py +9 -0
- cdp/protocol/tethering/methods/__init__.py +0 -0
- cdp/protocol/tethering/methods/service.py +43 -0
- cdp/protocol/tethering/methods/types.py +10 -0
- cdp/protocol/tethering/service.py +21 -0
- cdp/protocol/tethering/types.py +3 -0
- cdp/protocol/tracing/__init__.py +0 -0
- cdp/protocol/tracing/events/__init__.py +0 -0
- cdp/protocol/tracing/events/service.py +45 -0
- cdp/protocol/tracing/events/types.py +28 -0
- cdp/protocol/tracing/methods/__init__.py +0 -0
- cdp/protocol/tracing/methods/service.py +87 -0
- cdp/protocol/tracing/methods/types.py +54 -0
- cdp/protocol/tracing/service.py +21 -0
- cdp/protocol/tracing/types.py +34 -0
- cdp/protocol/web_audio/__init__.py +0 -0
- cdp/protocol/web_audio/events/__init__.py +0 -0
- cdp/protocol/web_audio/events/service.py +125 -0
- cdp/protocol/web_audio/events/types.py +56 -0
- cdp/protocol/web_audio/methods/__init__.py +0 -0
- cdp/protocol/web_audio/methods/service.py +54 -0
- cdp/protocol/web_audio/methods/types.py +17 -0
- cdp/protocol/web_audio/service.py +21 -0
- cdp/protocol/web_audio/types.py +66 -0
- cdp/protocol/web_authn/__init__.py +0 -0
- cdp/protocol/web_authn/events/__init__.py +0 -0
- cdp/protocol/web_authn/events/service.py +53 -0
- cdp/protocol/web_authn/events/types.py +21 -0
- cdp/protocol/web_authn/methods/__init__.py +0 -0
- cdp/protocol/web_authn/methods/service.py +164 -0
- cdp/protocol/web_authn/methods/types.py +61 -0
- cdp/protocol/web_authn/service.py +21 -0
- cdp/protocol/web_authn/types.py +54 -0
- cdp/py.typed +0 -0
- cdp/service.py +184 -0
- chromedeveloperprotocol_client-0.1.0.dist-info/METADATA +15 -0
- chromedeveloperprotocol_client-0.1.0.dist-info/RECORD +476 -0
- chromedeveloperprotocol_client-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
from jinja2_strcase import StrcaseExtension
|
|
2
|
+
from jinja2 import Environment
|
|
3
|
+
|
|
4
|
+
DOMAINS_TEMPLATE = """\
|
|
5
|
+
\"\"\"CDP Domains library for interacting with various domains.\"\"\"
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from .service import Client
|
|
10
|
+
{% for domain in domains %}
|
|
11
|
+
from .protocol.{{ domain['domain'] | to_snake }}.service import {{ domain['domain'] }}
|
|
12
|
+
{% endfor %}
|
|
13
|
+
|
|
14
|
+
class Domains:
|
|
15
|
+
\"\"\"
|
|
16
|
+
Collection of all CDP domains.
|
|
17
|
+
|
|
18
|
+
This class acts as a container for all available CDP domain services.
|
|
19
|
+
Each domain is lazily initialized when first accessed.
|
|
20
|
+
\"\"\"
|
|
21
|
+
def __init__(self, client: "Client"):
|
|
22
|
+
\"\"\"
|
|
23
|
+
Initialize the Domains container.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
client ("Client"): The parent CDP client instance.
|
|
27
|
+
\"\"\"
|
|
28
|
+
self.client = client
|
|
29
|
+
{% for domain in domains %}
|
|
30
|
+
self._{{ domain['domain'] | to_snake }}: Optional['{{ domain['domain'] }}'] = None
|
|
31
|
+
{% endfor %}
|
|
32
|
+
|
|
33
|
+
{% for domain in domains %}
|
|
34
|
+
@property
|
|
35
|
+
def {{ domain['domain'] | to_snake }}(self) -> '{{ domain['domain'] }}':
|
|
36
|
+
\"\"\"
|
|
37
|
+
{% if domain['description'] %}{{ domain['description'] | replace("\\n", " ") }}{% else %}Access the {{ domain['domain'] }} domain.{% endif %}
|
|
38
|
+
\"\"\"
|
|
39
|
+
if self._{{ domain['domain'] | to_snake }} is None:
|
|
40
|
+
from .protocol.{{ domain['domain'] | to_snake }}.service import {{ domain['domain'] }}
|
|
41
|
+
self._{{ domain['domain'] | to_snake }} = {{ domain['domain'] }}(client=self.client)
|
|
42
|
+
return self._{{ domain['domain'] | to_snake }}
|
|
43
|
+
|
|
44
|
+
{% endfor %}
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
SERVICE_TEMPLATE = """\
|
|
48
|
+
from typing import Optional, Dict, Any, Callable,Annotated, List
|
|
49
|
+
from operator import add
|
|
50
|
+
import websockets
|
|
51
|
+
import asyncio
|
|
52
|
+
import logging
|
|
53
|
+
import json
|
|
54
|
+
|
|
55
|
+
from .domains import Domains
|
|
56
|
+
from .generator.service import CDPGenerator
|
|
57
|
+
|
|
58
|
+
class Client(Domains):
|
|
59
|
+
\"\"\"
|
|
60
|
+
Core client for interacting with Chrome DevTools Protocol (CDP).
|
|
61
|
+
|
|
62
|
+
This class provides a high-level API to send commands and listen for events across
|
|
63
|
+
various CDP domains. It manages the underlying WebSocket connection and dispatches
|
|
64
|
+
messages to the appropriate handlers.
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
url (str): The WebSocket URL of the remote debugging target.
|
|
68
|
+
ws (websockets.ClientConnection): The active WebSocket connection.
|
|
69
|
+
listen_task (asyncio.Task): Background task processing incoming CDP messages.
|
|
70
|
+
id_counter (int): Counter for generating unique request IDs.
|
|
71
|
+
pending_requests (Dict[int, asyncio.Future]): Tracks outstanding requests by ID.
|
|
72
|
+
event_handlers (Dict[str, List[Callable]]): Registered callbacks for CDP events.
|
|
73
|
+
\"\"\"
|
|
74
|
+
def __init__(self, url: str, refresh: bool = False):
|
|
75
|
+
\"\"\"
|
|
76
|
+
Initialize the CDP Client.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
url (str): WebSocket debugger URL.
|
|
80
|
+
refresh (bool): If True, regenerates the CDP protocol definitions on initialization.
|
|
81
|
+
\"\"\"
|
|
82
|
+
super().__init__(self)
|
|
83
|
+
self.url = url
|
|
84
|
+
self.ws :Optional[websockets.ClientConnection] = None
|
|
85
|
+
self.listen_task :Optional[asyncio.Task] = None
|
|
86
|
+
self.id_counter: Annotated[int, add] = 0
|
|
87
|
+
self.pending_requests: Dict[int, asyncio.Future] = {}
|
|
88
|
+
self.event_handlers: Dict[str, List[Callable[[Any, Optional[str]], None]]] = {}
|
|
89
|
+
|
|
90
|
+
if refresh:
|
|
91
|
+
self.refresh()
|
|
92
|
+
|
|
93
|
+
async def __aenter__(self):
|
|
94
|
+
\"\"\"Connect to the WebSocket and start the background listener.\"\"\"
|
|
95
|
+
self.ws = await websockets.connect(self.url,max_size=100*1024*1024)
|
|
96
|
+
self.listen_task = asyncio.create_task(self.listen())
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
100
|
+
\"\"\"Cancel the listener, clear pending requests, and close the WebSocket.\"\"\"
|
|
101
|
+
for future in self.pending_requests.values():
|
|
102
|
+
if not future.done():
|
|
103
|
+
future.set_exception(Exception("WebSocket connection closed"))
|
|
104
|
+
self.pending_requests.clear()
|
|
105
|
+
if self.listen_task:
|
|
106
|
+
try:
|
|
107
|
+
self.listen_task.cancel()
|
|
108
|
+
await self.listen_task
|
|
109
|
+
except asyncio.CancelledError:
|
|
110
|
+
pass
|
|
111
|
+
finally:
|
|
112
|
+
self.listen_task = None
|
|
113
|
+
if self.ws:
|
|
114
|
+
await self.ws.close()
|
|
115
|
+
self.ws = None
|
|
116
|
+
|
|
117
|
+
async def send(self, method: str, params: Optional[dict] = None,session_id: Optional[str] = None) -> Any:
|
|
118
|
+
\"\"\"
|
|
119
|
+
Send a CDP command and wait for the result.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
method (str): The CDP method name (e.g., 'Page.navigate').
|
|
123
|
+
params (dict, optional): Parameters for the method.
|
|
124
|
+
session_id (str, optional): Target session ID for flat protocol usage.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Any: The 'result' object from the CDP response.
|
|
128
|
+
|
|
129
|
+
Raises:
|
|
130
|
+
Exception: If the CDP returns an error or the connection is lost.
|
|
131
|
+
\"\"\"
|
|
132
|
+
self.id_counter+=1
|
|
133
|
+
future = asyncio.Future()
|
|
134
|
+
self.pending_requests[self.id_counter] = future
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
message = {"id": self.id_counter, "method": method, "params": params or {}}
|
|
138
|
+
if session_id:
|
|
139
|
+
message['sessionId'] = session_id
|
|
140
|
+
await self.ws.send(json.dumps(message))
|
|
141
|
+
return await future
|
|
142
|
+
except Exception as e:
|
|
143
|
+
self.pending_requests.pop(self.id_counter, None)
|
|
144
|
+
raise e
|
|
145
|
+
|
|
146
|
+
def on(self, event: str, callback: Callable[[Any, Optional[str]], None]) -> None:
|
|
147
|
+
\"\"\"
|
|
148
|
+
Register an event handler. Alias for `Client.register`.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
event (str): The CDP event name (e.g., 'Page.loadEventFired').
|
|
152
|
+
callback (callable): Function called with (params, session_id).
|
|
153
|
+
\"\"\"
|
|
154
|
+
self.register(event, callback)
|
|
155
|
+
|
|
156
|
+
def register(self, event: str, callback: Callable[[Any, Optional[str]], None]) -> None:
|
|
157
|
+
\"\"\"
|
|
158
|
+
Register a handler for a specific CDP event.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
event (str): The CDP event name.
|
|
162
|
+
callback (callable): Function called with (params, session_id).
|
|
163
|
+
\"\"\"
|
|
164
|
+
if event not in self.event_handlers:
|
|
165
|
+
self.event_handlers[event] = []
|
|
166
|
+
self.event_handlers[event].append(callback)
|
|
167
|
+
|
|
168
|
+
def unregister(self, event: str) -> None:
|
|
169
|
+
\"\"\"
|
|
170
|
+
Unregister all handlers for a specific CDP event.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
event (str): The CDP event name.
|
|
174
|
+
\"\"\"
|
|
175
|
+
if event in self.event_handlers:
|
|
176
|
+
del self.event_handlers[event]
|
|
177
|
+
|
|
178
|
+
def refresh(self):
|
|
179
|
+
\"\"\"
|
|
180
|
+
Refresh the CDP protocol definitions by fetching latest schemas and
|
|
181
|
+
regenerating the client source code on disk.
|
|
182
|
+
\"\"\"
|
|
183
|
+
generator = CDPGenerator()
|
|
184
|
+
generator.generate()
|
|
185
|
+
|
|
186
|
+
async def listen(self):
|
|
187
|
+
\"\"\"
|
|
188
|
+
Internal background loop that receives messages from the WebSocket.
|
|
189
|
+
Dispatches responses to pending request futures and events to registered handlers.
|
|
190
|
+
\"\"\"
|
|
191
|
+
while True:
|
|
192
|
+
try:
|
|
193
|
+
message = await self.ws.recv()
|
|
194
|
+
data = json.loads(message)
|
|
195
|
+
if "id" in data:
|
|
196
|
+
# Method
|
|
197
|
+
request_id=data["id"]
|
|
198
|
+
logging.debug(f"Received method response: {data}")
|
|
199
|
+
if request_id not in self.pending_requests:
|
|
200
|
+
continue
|
|
201
|
+
future = self.pending_requests.pop(request_id)
|
|
202
|
+
if not future.done():
|
|
203
|
+
if "error" in data:
|
|
204
|
+
future.set_exception(Exception(data.get("error")))
|
|
205
|
+
else:
|
|
206
|
+
future.set_result(data.get("result"))
|
|
207
|
+
elif 'method' in data:
|
|
208
|
+
# Event
|
|
209
|
+
method=data.get("method")
|
|
210
|
+
params = data.get("params", {})
|
|
211
|
+
session_id=data.get("sessionId")
|
|
212
|
+
logging.debug(f"Received event: {data}")
|
|
213
|
+
if method not in self.event_handlers:
|
|
214
|
+
continue
|
|
215
|
+
|
|
216
|
+
handlers = self.event_handlers[method]
|
|
217
|
+
for handler in handlers:
|
|
218
|
+
try:
|
|
219
|
+
if asyncio.iscoroutinefunction(handler):
|
|
220
|
+
asyncio.create_task(handler(params,session_id))
|
|
221
|
+
else:
|
|
222
|
+
handler(params,session_id)
|
|
223
|
+
except Exception as e:
|
|
224
|
+
logging.error(f"Error in event handler for {method}: {e}")
|
|
225
|
+
continue
|
|
226
|
+
except websockets.exceptions.ConnectionClosed:
|
|
227
|
+
logging.info("CDP WebSocket connection closed")
|
|
228
|
+
break
|
|
229
|
+
except Exception as e:
|
|
230
|
+
logging.error(f"Error in CDP listen loop: {e}")
|
|
231
|
+
break
|
|
232
|
+
"""
|
|
233
|
+
|
|
234
|
+
class ClientGenerator:
|
|
235
|
+
def __init__(self, protocol_package: str, package_name: str):
|
|
236
|
+
self.env=Environment(trim_blocks=True,lstrip_blocks=True,extensions=[StrcaseExtension])
|
|
237
|
+
self.protocol_package = protocol_package
|
|
238
|
+
self.package_name = package_name
|
|
239
|
+
|
|
240
|
+
def generate_domains(self, domains: list[dict]):
|
|
241
|
+
template = self.env.from_string(DOMAINS_TEMPLATE)
|
|
242
|
+
return template.render(domains=domains, protocol_package=self.protocol_package).strip()
|
|
243
|
+
|
|
244
|
+
def generate_service(self):
|
|
245
|
+
template = self.env.from_string(SERVICE_TEMPLATE)
|
|
246
|
+
return template.render().strip()
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
from jinja2 import Environment
|
|
2
|
+
from jinja2_strcase import StrcaseExtension
|
|
3
|
+
from .method_generator import MethodGenerator
|
|
4
|
+
from .event_generator import EventGenerator
|
|
5
|
+
|
|
6
|
+
METHODS_SERVICE_TEMPLATE = """\
|
|
7
|
+
\"\"\"CDP {{ domain_name }} Domain Methods\"\"\"
|
|
8
|
+
{% for import_ in imports %}
|
|
9
|
+
{{ import_ }}
|
|
10
|
+
{% endfor %}
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ....service import Client
|
|
14
|
+
|
|
15
|
+
class {{ class_name }}:
|
|
16
|
+
\"\"\"
|
|
17
|
+
Methods for the {{ domain_name }} domain.
|
|
18
|
+
\"\"\"
|
|
19
|
+
def __init__(self, client: "Client"):
|
|
20
|
+
\"\"\"
|
|
21
|
+
Initialize the {{ domain_name }} methods.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
client ("Client"): The parent CDP client instance.
|
|
25
|
+
\"\"\"
|
|
26
|
+
self.client = client
|
|
27
|
+
|
|
28
|
+
{% for implementation in method_implementations %}
|
|
29
|
+
{{ implementation | indent(4) }}
|
|
30
|
+
{% endfor %}
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
EVENTS_SERVICE_TEMPLATE = """\
|
|
34
|
+
\"\"\"CDP {{ domain_name }} Domain Events\"\"\"
|
|
35
|
+
{% for import_ in imports %}
|
|
36
|
+
{{ import_ }}
|
|
37
|
+
{% endfor %}
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from ....service import Client
|
|
41
|
+
|
|
42
|
+
class {{ class_name }}:
|
|
43
|
+
\"\"\"
|
|
44
|
+
Events for the {{ domain_name }} domain.
|
|
45
|
+
\"\"\"
|
|
46
|
+
def __init__(self, client: "Client"):
|
|
47
|
+
\"\"\"
|
|
48
|
+
Initialize the {{ domain_name }} events.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
client ("Client"): The parent CDP client instance.
|
|
52
|
+
\"\"\"
|
|
53
|
+
self.client = client
|
|
54
|
+
|
|
55
|
+
{% for implementation in event_implementations %}
|
|
56
|
+
{{ implementation | indent(4) }}
|
|
57
|
+
{% endfor %}
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
DOMAIN_SERVICE_TEMPLATE = """\
|
|
61
|
+
\"\"\"CDP {{ domain_name }} Domain\"\"\"
|
|
62
|
+
from typing import TYPE_CHECKING
|
|
63
|
+
from .methods.service import {{ domain_name }}Methods
|
|
64
|
+
from .events.service import {{ domain_name }}Events
|
|
65
|
+
|
|
66
|
+
if TYPE_CHECKING:
|
|
67
|
+
from ...service import Client
|
|
68
|
+
|
|
69
|
+
class {{ domain_name }}({{ domain_name }}Methods, {{ domain_name }}Events):
|
|
70
|
+
\"\"\"
|
|
71
|
+
{{ domain_description | replace("\\n", " ") }}
|
|
72
|
+
\"\"\"
|
|
73
|
+
def __init__(self, client: "Client"):
|
|
74
|
+
\"\"\"
|
|
75
|
+
Initialize the {{ domain_name }} domain.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
client ("Client"): The parent CDP client instance.
|
|
79
|
+
\"\"\"
|
|
80
|
+
{{ domain_name }}Methods.__init__(self, client)
|
|
81
|
+
{{ domain_name }}Events.__init__(self, client)
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
class DomainGenerator:
|
|
85
|
+
def __init__(self, method_generator: MethodGenerator, event_generator: EventGenerator, package_name: str):
|
|
86
|
+
self.method_generator = method_generator
|
|
87
|
+
self.event_generator = event_generator
|
|
88
|
+
self.package_name = package_name
|
|
89
|
+
self.env = Environment(trim_blocks=True, lstrip_blocks=True, extensions=[StrcaseExtension])
|
|
90
|
+
|
|
91
|
+
def generate_methods_service(self, domain: dict) -> str:
|
|
92
|
+
domain_name = domain['domain']
|
|
93
|
+
self.method_generator.current_domain = domain_name
|
|
94
|
+
self.method_generator.clear()
|
|
95
|
+
|
|
96
|
+
methods = domain.get('commands', [])
|
|
97
|
+
method_implementations = []
|
|
98
|
+
for method in methods:
|
|
99
|
+
if not method.get('deprecated', False):
|
|
100
|
+
code = self.method_generator.generate_method_implementation(method)
|
|
101
|
+
method_implementations.append(code)
|
|
102
|
+
|
|
103
|
+
imports = self.method_generator.imports.copy()
|
|
104
|
+
imports.update(self.method_generator.type_checking_imports)
|
|
105
|
+
imports.add("from .types import *")
|
|
106
|
+
imports.add("from ..types import *") # Import shared types
|
|
107
|
+
imports.add("from typing import Optional, Dict, Any, Callable, TYPE_CHECKING")
|
|
108
|
+
|
|
109
|
+
class_name = f"{domain_name}Methods"
|
|
110
|
+
template = self.env.from_string(METHODS_SERVICE_TEMPLATE)
|
|
111
|
+
return template.render(
|
|
112
|
+
domain_name=domain_name,
|
|
113
|
+
class_name=class_name,
|
|
114
|
+
imports=sorted(imports),
|
|
115
|
+
method_implementations=method_implementations
|
|
116
|
+
).strip()
|
|
117
|
+
|
|
118
|
+
def generate_events_service(self, domain: dict) -> str:
|
|
119
|
+
domain_name = domain['domain']
|
|
120
|
+
self.event_generator.current_domain = domain_name
|
|
121
|
+
self.event_generator.clear()
|
|
122
|
+
|
|
123
|
+
events = domain.get('events', [])
|
|
124
|
+
event_implementations = []
|
|
125
|
+
for event in events:
|
|
126
|
+
if not event.get('deprecated', False):
|
|
127
|
+
code = self.event_generator.generate_event_implementation(event)
|
|
128
|
+
event_implementations.append(code)
|
|
129
|
+
|
|
130
|
+
imports = self.event_generator.imports.copy()
|
|
131
|
+
imports.update(self.event_generator.type_checking_imports)
|
|
132
|
+
imports.add("from .types import *")
|
|
133
|
+
imports.add("from ..types import *")
|
|
134
|
+
imports.add("from typing import Optional, Dict, Any, Callable, TYPE_CHECKING")
|
|
135
|
+
|
|
136
|
+
class_name = f"{domain_name}Events"
|
|
137
|
+
template = self.env.from_string(EVENTS_SERVICE_TEMPLATE)
|
|
138
|
+
return template.render(
|
|
139
|
+
domain_name=domain_name,
|
|
140
|
+
class_name=class_name,
|
|
141
|
+
imports=sorted(imports),
|
|
142
|
+
event_implementations=event_implementations
|
|
143
|
+
).strip()
|
|
144
|
+
|
|
145
|
+
def generate_domain_service(self, domain: dict) -> str:
|
|
146
|
+
domain_name = domain['domain']
|
|
147
|
+
domain_description = domain.get('description', f'Access the {domain_name} domain.')
|
|
148
|
+
template = self.env.from_string(DOMAIN_SERVICE_TEMPLATE)
|
|
149
|
+
return template.render(domain_name=domain_name, domain_description=domain_description).strip()
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
from jinja2 import Environment
|
|
2
|
+
from jinja2_strcase import StrcaseExtension
|
|
3
|
+
import inflection
|
|
4
|
+
|
|
5
|
+
EVENT_SERVICES_TEMPLATE = """\
|
|
6
|
+
\"\"\"CDP {{ domain_name }} Events\"\"\"
|
|
7
|
+
|
|
8
|
+
from client.service import CDPClient
|
|
9
|
+
from typing import TypedDict, Optional, Callable
|
|
10
|
+
from protocol.{{ domain_name | to_snake }}.events.types import *
|
|
11
|
+
|
|
12
|
+
class {{ domain_name }}Events:
|
|
13
|
+
{% if event_implementations | length > 0 %}
|
|
14
|
+
def __init__(self,client:CDPClient):
|
|
15
|
+
self.client=client
|
|
16
|
+
{% for implementation in event_implementations %}
|
|
17
|
+
{{ implementation | indent(4) }}
|
|
18
|
+
{% endfor %}
|
|
19
|
+
{% else %}
|
|
20
|
+
pass
|
|
21
|
+
{% endif %}
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
EVENT_IMPLEMENTATION_TEMPLATE = """\
|
|
25
|
+
def on_{{ event_name | to_snake }}(self, callback: Callable[[{{ event_name }}Event,Optional[str]], None]=None) -> None:
|
|
26
|
+
\"\"\"
|
|
27
|
+
{% if event_description %}{{ event_description | replace("\\n", " ") }}{% else %}No description available for {{ event_name }}.{% endif %}
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
callback (callable, optional): Function called when the event is fired.
|
|
31
|
+
The callback receives (params: {{ event_name }}Event, session_id: Optional[str]).
|
|
32
|
+
\"\"\"
|
|
33
|
+
self.client.on('{{ domain_name }}.{{ event_name }}', callback)
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
EVENT_TYPES_TEMPLATE = """\
|
|
37
|
+
\"\"\"CDP {{ domain_name }} Events\"\"\"
|
|
38
|
+
|
|
39
|
+
{% for import_ in imports %}
|
|
40
|
+
{{ import_ }}
|
|
41
|
+
{% endfor %}
|
|
42
|
+
{% if type_checking_imports %}
|
|
43
|
+
|
|
44
|
+
from typing import TYPE_CHECKING
|
|
45
|
+
if TYPE_CHECKING:
|
|
46
|
+
{% for type_checking_import in type_checking_imports %}
|
|
47
|
+
{{ type_checking_import }}
|
|
48
|
+
{% endfor %}
|
|
49
|
+
{% endif %}
|
|
50
|
+
|
|
51
|
+
{% for definition in event_definitions_code %}
|
|
52
|
+
{{ definition }}
|
|
53
|
+
{% endfor %}
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
EVENT_DEFINITION_TEMPLATE = """\
|
|
57
|
+
class {{event_name}}Event(TypedDict, total={{total}}):
|
|
58
|
+
{% if not required_parameters and not optional_parameters %}
|
|
59
|
+
pass
|
|
60
|
+
{% else %}
|
|
61
|
+
{% if required_parameters %}
|
|
62
|
+
{% for parameter in required_parameters %}
|
|
63
|
+
{{ parameter['name'] }}: '{{ parameter['type'] }}'
|
|
64
|
+
{% if parameter['description'] %}
|
|
65
|
+
\"\"\"{{ parameter['description'] | replace('\\n', ' ') | replace('`', '') }}\"\"\"
|
|
66
|
+
{% endif %}
|
|
67
|
+
{% endfor %}
|
|
68
|
+
{% endif %}
|
|
69
|
+
{% if optional_parameters %}
|
|
70
|
+
{% for parameter in optional_parameters %}
|
|
71
|
+
{{ parameter['name'] }}: NotRequired['{{ parameter['type'] }}']
|
|
72
|
+
{% if parameter['description'] %}
|
|
73
|
+
\"\"\"{{ parameter['description'] | replace('\\n', ' ') | replace('`', '') }}\"\"\"
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% endfor %}
|
|
76
|
+
{% endif %}
|
|
77
|
+
{% endif %}
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
class EventGenerator:
|
|
81
|
+
def __init__(self,path, protocol_package:str):
|
|
82
|
+
self.path = path
|
|
83
|
+
self.protocol_package = protocol_package
|
|
84
|
+
self.current_domain:str=None
|
|
85
|
+
self.env=Environment(trim_blocks=True,lstrip_blocks=True,extensions=[StrcaseExtension])
|
|
86
|
+
self.imports = set()
|
|
87
|
+
self.generated_events = set()
|
|
88
|
+
self.type_checking_imports = set()
|
|
89
|
+
|
|
90
|
+
def clear(self):
|
|
91
|
+
self.imports.clear()
|
|
92
|
+
self.generated_events.clear()
|
|
93
|
+
self.type_checking_imports.clear()
|
|
94
|
+
|
|
95
|
+
def generate_event_services(self,domain:dict):
|
|
96
|
+
self.current_domain=domain.get('domain')
|
|
97
|
+
events=domain.get('events',[])
|
|
98
|
+
event_implementations=[self.generate_event_implementation(event) for event in events]
|
|
99
|
+
template = self.env.from_string(EVENT_SERVICES_TEMPLATE)
|
|
100
|
+
code = template.render(
|
|
101
|
+
domain_name=self.current_domain,
|
|
102
|
+
event_implementations=event_implementations,
|
|
103
|
+
)
|
|
104
|
+
return code.strip()
|
|
105
|
+
|
|
106
|
+
def generate_event_implementation(self,event:dict):
|
|
107
|
+
event_name=event.get('name')
|
|
108
|
+
event_description=event.get('description','')
|
|
109
|
+
template = self.env.from_string(EVENT_IMPLEMENTATION_TEMPLATE)
|
|
110
|
+
code = template.render(
|
|
111
|
+
event_name=event_name,
|
|
112
|
+
domain_name=self.current_domain,
|
|
113
|
+
event_description=event_description
|
|
114
|
+
)
|
|
115
|
+
return code.strip()
|
|
116
|
+
|
|
117
|
+
def generate_event_types(self,domain:dict):
|
|
118
|
+
self.current_domain=domain.get('domain')
|
|
119
|
+
events=domain.get('events',[])
|
|
120
|
+
self.clear()
|
|
121
|
+
self.imports.add("from typing import TypedDict, NotRequired, Required, Literal, Any, Dict, Union, Optional, List, Set, Tuple")
|
|
122
|
+
for event in events:
|
|
123
|
+
self.generated_events.add(event.get('name'))
|
|
124
|
+
|
|
125
|
+
event_definitions_code=[self.generate_event_definition(event) for event in events if not event.get('deprecated',False)]
|
|
126
|
+
template = self.env.from_string(EVENT_TYPES_TEMPLATE)
|
|
127
|
+
code = template.render(
|
|
128
|
+
domain_name=self.current_domain,
|
|
129
|
+
event_definitions_code=event_definitions_code,
|
|
130
|
+
imports=sorted(filter(lambda x: not x.startswith(f'from {self.protocol_package}.{self.current_domain}.types import'),self.imports)),
|
|
131
|
+
type_checking_imports=sorted(self.type_checking_imports),
|
|
132
|
+
)
|
|
133
|
+
return code.strip()
|
|
134
|
+
|
|
135
|
+
def generate_event_definition(self,event_definition):
|
|
136
|
+
event_name=event_definition.get('name')
|
|
137
|
+
parameters=event_definition.get('parameters',[])
|
|
138
|
+
required_parameters=[]
|
|
139
|
+
optional_parameters=[]
|
|
140
|
+
for parameter in parameters:
|
|
141
|
+
parameter['type'] = self.resolve_parameter_type(parameter)
|
|
142
|
+
if parameter.get('optional',False):
|
|
143
|
+
optional_parameters.append(parameter)
|
|
144
|
+
else:
|
|
145
|
+
required_parameters.append(parameter)
|
|
146
|
+
|
|
147
|
+
total = not (optional_parameters and not required_parameters)
|
|
148
|
+
template = self.env.from_string(EVENT_DEFINITION_TEMPLATE)
|
|
149
|
+
code = template.render(
|
|
150
|
+
total=total,
|
|
151
|
+
event_name=event_name,
|
|
152
|
+
required_parameters=required_parameters,
|
|
153
|
+
optional_parameters=optional_parameters,
|
|
154
|
+
)
|
|
155
|
+
self.generated_events.add(event_name)
|
|
156
|
+
return code.strip()
|
|
157
|
+
|
|
158
|
+
def resolve_parameter_type(self, parameter:dict):
|
|
159
|
+
if "$ref" in parameter:
|
|
160
|
+
return self.resolve_type_reference(parameter)
|
|
161
|
+
parameter_type=parameter.get("type","any")
|
|
162
|
+
match parameter_type:
|
|
163
|
+
case 'object':
|
|
164
|
+
return "Dict[str, Any]"
|
|
165
|
+
case 'array':
|
|
166
|
+
items=parameter.get('items',{})
|
|
167
|
+
return f"List[{self.resolve_type_reference(items) if '$ref' in items else self.map_primitive_type(items.get('type'))}]"
|
|
168
|
+
case 'string':
|
|
169
|
+
if 'enum' in parameter:
|
|
170
|
+
return f"Literal[{', '.join(f'\"{v}\"' for v in parameter.get('enum'))}]"
|
|
171
|
+
else:
|
|
172
|
+
return "str"
|
|
173
|
+
case _:
|
|
174
|
+
return self.map_primitive_type(parameter_type)
|
|
175
|
+
|
|
176
|
+
def resolve_type_reference(self, type_ref:dict):
|
|
177
|
+
ref=type_ref.get('$ref')
|
|
178
|
+
if '.' in ref:
|
|
179
|
+
parts=ref.split('.')
|
|
180
|
+
type_name=parts[1]
|
|
181
|
+
domain=inflection.underscore(parts[0])
|
|
182
|
+
self.type_checking_imports.add(f"from {self.protocol_package}.{domain}.types import {type_name}")
|
|
183
|
+
return type_name
|
|
184
|
+
else:
|
|
185
|
+
domain=inflection.underscore(self.current_domain)
|
|
186
|
+
self.type_checking_imports.add(f"from {self.protocol_package}.{domain}.types import {ref}")
|
|
187
|
+
return ref
|
|
188
|
+
|
|
189
|
+
def map_primitive_type(self, type_name: str):
|
|
190
|
+
match type_name:
|
|
191
|
+
case "string":
|
|
192
|
+
return "str"
|
|
193
|
+
case "object":
|
|
194
|
+
return "Dict[str, Any]"
|
|
195
|
+
case "number":
|
|
196
|
+
return "float"
|
|
197
|
+
case "integer":
|
|
198
|
+
return "int"
|
|
199
|
+
case "boolean":
|
|
200
|
+
return "bool"
|
|
201
|
+
case _:
|
|
202
|
+
return "Any"
|