Skip to main content

Sending CDP Commands

Use the send() method on Tab or Browser objects to send CDP commands:

Command Structure

CDP commands are generator objects created by calling methods from CDP domain modules:

Return Values

CDP commands return different types based on the command:

Common CDP Tasks

Screenshots

JavaScript Execution

DOM Manipulation

Network Monitoring

Input Simulation

Emulation

Event Handling

Listen to CDP events using event handlers:

Common Events

Request Interception

Intercept and modify network requests:

Performance Monitoring

Storage Access

Advanced Examples

Capture network response bodies

Custom device emulation

Best Practices

Enable domains before use - Many CDP commands require enabling their domain first with domain.enable().
Handle async events - Event handlers may need to use asyncio.create_task() for async operations.
Check return types - CDP commands return different types. Check the type hints or documentation.
Cleanup handlers - Remove event handlers when done to prevent memory leaks.

See Also