Principle:SeleniumHQ Selenium WebDriver Session For CDP
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, DevTools, Session_Management |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Establishing a WebDriver session with capabilities that enable Chrome DevTools Protocol access for advanced browser control beyond standard WebDriver commands.
Description
While standard WebDriver sessions provide W3C-compliant browser automation, CDP access requires additional capabilities. When a Chrome/Chromium session is created, the driver returns the se:cdp capability containing a WebSocket URL for the CDP endpoint. The session must be established with a Chromium-based browser (Chrome or Edge) that implements the HasDevTools interface. Specifically, ChromeDriver extends ChromiumDriver, which implements HasDevTools and HasBiDi. The HasDevTools interface provides both getDevTools() (which throws on failure) and maybeGetDevTools() (which returns an Optional<DevTools>). This principle is the prerequisite for all CDP-based operations.
Usage
Apply this principle when you need advanced browser features beyond standard WebDriver: network interception, console log capture, geolocation emulation, performance monitoring, or JavaScript heap profiling. Only available with Chromium-based browsers (Chrome and Edge).
Theoretical Basis
# Pseudocode: CDP-Enabled Session
1. Create ChromeDriver (or EdgeDriver)
- ChromeDriver extends ChromiumDriver which implements HasDevTools
2. Session response includes: { "se:cdp": "ws://localhost:PORT/devtools/..." }
3. Call driver.getDevTools() to obtain DevTools client
- Internally calls maybeGetDevTools() which returns Optional<DevTools>
- Throws DevToolsException if connection cannot be established
4. Call devTools.createSession() to attach to a browser target
5. Use DevTools client for CDP operations (send commands, listen for events)