What it does
The script:- Sets up handlers for network request and response events
- Navigates to Google and performs a search
- Logs all HTTP requests with their headers
- Logs all HTTP responses
- Downloads all URLs found on the page
Complete code
Key techniques
CDP event handlers
Add handlers to listen for Chrome DevTools Protocol events:Request inspection
Access detailed request information in your handler:Response inspection
Access response data:URL extraction
Get all URLs from the current page:Navigation methods
Use browser navigation controls:Input manipulation
Clear and modify input fields:Running the example
- Save the code to a file (e.g.,
network_monitor.py) - Run it with Python:
- Watch the console output to see all network requests and responses
Use cases
- Debugging: See exactly what requests your automation is making
- Performance analysis: Identify slow or failing requests
- API inspection: Discover undocumented API endpoints
- Security testing: Analyze headers and authentication flows
- Data extraction: Capture API responses for further processing
Available CDP events
You can listen to many other CDP events beyond network monitoring:cdp.network.RequestWillBeSent- Before a request is sentcdp.network.ResponseReceived- When a response is receivedcdp.network.LoadingFinished- When a resource finishes loadingcdp.network.LoadingFailed- When a resource fails to loadcdp.page.FrameNavigated- When a frame navigates- And many more from the Chrome DevTools Protocol specification