cdp module. This allows you to control the browser at the lowest level and access features not exposed through the high-level API.
Overview
The CDP module contains all Chrome DevTools Protocol domains and methods. Each domain provides methods to control different aspects of the browser:- page: Page navigation, lifecycle, and content
- network: Network monitoring and modification
- runtime: JavaScript execution and evaluation
- dom: DOM tree inspection and manipulation
- fetch: Request interception and modification
- browser: Browser-level operations
- And many more…
Importing CDP
Using CDP commands
CDP commands are sent using thesend() method on a Connection (or Tab/Browser):
Available domains
The CDP module includes the following domains:Core domains
page
Page navigation, lifecycle events, screenshots, and PDF generation
network
Network monitoring, request/response inspection, and modification
runtime
JavaScript execution, evaluation, and console access
dom
DOM tree inspection, node selection, and attribute access
Advanced domains
fetch
Request interception, modification, and mocking
browser
Browser contexts, permissions, and downloads
emulation
Device emulation, geolocation, and user agent overrides
input_
Keyboard and mouse input simulation
Other domains
accessibility- Accessibility tree inspectionanimation- CSS animation controlaudits- Lighthouse auditscss- CSS inspection and modificationdebugger- JavaScript debuggingstorage- Cookies, local storage, and cacheperformance- Performance metrics and profiling- And many more… (see ~/workspace/source/zendriver/cdp/init.py)
Common CDP patterns
Navigation and waiting
JavaScript execution
Network monitoring
DOM manipulation
Screenshot and PDF
Cookies and storage
Device emulation
Event handlers
Many CDP domains emit events that you can listen to:Error handling
CDP commands can raiseProtocolException if they fail:
Non-blocking commands
In some cases, you may need to send CDP commands without blocking (e.g., during request interception):Related
- Connection API - Send CDP commands via Connection
- Expect Methods - Wait for network events
- Intercept - Request interception with CDP Fetch
- Official CDP Documentation - Complete protocol reference