0
# CDP Domains
1
2
Direct access to all generated Chrome DevTools Protocol domains for advanced use cases requiring protocol-level control. Includes 41+ domains with full type-safe Java bindings for Chrome version 105.
3
4
## Capabilities
5
6
### Core Stable Domains
7
8
The most commonly used and stable CDP domains for browser automation.
9
10
#### Runtime Domain
11
12
JavaScript runtime API for code execution, object inspection, and runtime control.
13
14
```java { .api }
15
import org.openqa.selenium.devtools.v105.runtime.Runtime;
16
import org.openqa.selenium.devtools.v105.runtime.model.*;
17
18
// Enable/disable runtime domain
19
public static Command<Void> enable();
20
public static Command<Void> disable();
21
22
// JavaScript evaluation
23
public static Command<EvaluateResponse> evaluate(String expression);
24
public static Command<EvaluateResponse> evaluate(String expression,
25
Optional<String> objectGroup, Optional<Boolean> includeCommandLineAPI);
26
27
// Object inspection
28
public static Command<GetPropertiesResponse> getProperties(RemoteObjectId objectId);
29
public static Command<Void> releaseObject(RemoteObjectId objectId);
30
31
// Console and binding events
32
public static Event<ConsoleAPICalled> consoleAPICalled();
33
public static Event<ExceptionThrown> exceptionThrown();
34
public static Event<BindingCalled> bindingCalled();
35
```
36
37
**Usage Examples:**
38
39
```java
40
// Direct runtime evaluation
41
devTools.send(Runtime.enable());
42
43
EvaluateResponse result = devTools.send(Runtime.evaluate("document.title"));
44
System.out.println("Page title: " + result.getResult().getValue());
45
46
// Object inspection
47
devTools.send(Runtime.evaluate("document.body", Optional.empty(), Optional.of(true)))
48
.getResult().getObjectId()
49
.ifPresent(objectId -> {
50
GetPropertiesResponse props = devTools.send(Runtime.getProperties(objectId));
51
props.getResult().forEach(prop ->
52
System.out.println(prop.getName() + ": " + prop.getValue()));
53
});
54
```
55
56
#### Network Domain
57
58
Network control and monitoring at the protocol level.
59
60
```java { .api }
61
import org.openqa.selenium.devtools.v105.network.Network;
62
import org.openqa.selenium.devtools.v105.network.model.*;
63
64
// Enable/disable network domain
65
public static Command<Void> enable();
66
public static Command<Void> disable();
67
68
// Network configuration
69
public static Command<Void> setUserAgentOverride(String userAgent, Optional<String> acceptLanguage, Optional<String> platform);
70
public static Command<Void> setCacheDisabled(Boolean cacheDisabled);
71
public static Command<Void> setBypassServiceWorker(Boolean bypass);
72
73
// Request/response events
74
public static Event<RequestWillBeSent> requestWillBeSent();
75
public static Event<ResponseReceived> responseReceived();
76
public static Event<LoadingFinished> loadingFinished();
77
public static Event<LoadingFailed> loadingFailed();
78
```
79
80
**Usage Examples:**
81
82
```java
83
// Monitor network traffic
84
devTools.send(Network.enable());
85
86
Network.requestWillBeSent().addListener(request -> {
87
System.out.println("Request: " + request.getRequest().getMethod() + " " + request.getRequest().getUrl());
88
});
89
90
Network.responseReceived().addListener(response -> {
91
System.out.println("Response: " + response.getResponse().getStatus() + " " + response.getResponse().getUrl());
92
});
93
```
94
95
#### Page Domain
96
97
Page lifecycle, navigation, and document control.
98
99
```java { .api }
100
import org.openqa.selenium.devtools.v105.page.Page;
101
import org.openqa.selenium.devtools.v105.page.model.*;
102
103
// Enable/disable page domain
104
public static Command<Void> enable();
105
public static Command<Void> disable();
106
107
// Navigation
108
public static Command<NavigateResponse> navigate(String url);
109
public static Command<Void> reload(Optional<Boolean> ignoreCache, Optional<String> scriptToEvaluateOnLoad);
110
111
// Script injection
112
public static Command<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String source);
113
public static Command<Void> removeScriptToEvaluateOnNewDocument(ScriptIdentifier identifier);
114
115
// Page events
116
public static Event<FrameNavigated> frameNavigated();
117
public static Event<LoadEventFired> loadEventFired();
118
public static Event<DomContentEventFired> domContentEventFired();
119
```
120
121
**Usage Examples:**
122
123
```java
124
// Page navigation and events
125
devTools.send(Page.enable());
126
127
Page.frameNavigated().addListener(nav ->
128
System.out.println("Navigated to: " + nav.getFrame().getUrl()));
129
130
Page.loadEventFired().addListener(event ->
131
System.out.println("Page load completed at: " + event.getTimestamp()));
132
133
// Navigate programmatically
134
NavigateResponse navResult = devTools.send(Page.navigate("https://example.com"));
135
System.out.println("Navigation ID: " + navResult.getLoaderId());
136
```
137
138
### Debugging and Development Domains
139
140
Domains for debugging JavaScript and performance analysis.
141
142
#### Debugger Domain
143
144
JavaScript debugging capabilities including breakpoints and execution control.
145
146
```java { .api }
147
import org.openqa.selenium.devtools.v105.debugger.Debugger;
148
import org.openqa.selenium.devtools.v105.debugger.model.*;
149
150
// Enable/disable debugger
151
public static Command<Void> enable();
152
public static Command<Void> disable();
153
154
// Breakpoint management
155
public static Command<SetBreakpointByUrlResponse> setBreakpointByUrl(int lineNumber, String url);
156
public static Command<Void> removeBreakpoint(BreakpointId breakpointId);
157
158
// Execution control
159
public static Command<Void> resume();
160
public static Command<Void> stepOver();
161
public static Command<Void> stepInto();
162
public static Command<Void> stepOut();
163
164
// Debugger events
165
public static Event<Paused> paused();
166
public static Event<Resumed> resumed();
167
public static Event<ScriptParsed> scriptParsed();
168
```
169
170
#### Profiler Domain
171
172
Performance profiling for JavaScript execution analysis.
173
174
```java { .api }
175
import org.openqa.selenium.devtools.v105.profiler.Profiler;
176
import org.openqa.selenium.devtools.v105.profiler.model.*;
177
178
// Enable/disable profiler
179
public static Command<Void> enable();
180
public static Command<Void> disable();
181
182
// Profiling control
183
public static Command<Void> start();
184
public static Command<StopResponse> stop();
185
186
// Sampling configuration
187
public static Command<Void> setSamplingInterval(int interval);
188
189
// Profile events
190
public static Event<ConsoleProfileStarted> consoleProfileStarted();
191
public static Event<ConsoleProfileFinished> consoleProfileFinished();
192
```
193
194
### Browser Control Domains
195
196
Domains for browser-level control and emulation.
197
198
#### Browser Domain
199
200
Browser-level operations and information.
201
202
```java { .api }
203
import org.openqa.selenium.devtools.v105.browser.Browser;
204
import org.openqa.selenium.devtools.v105.browser.model.*;
205
206
// Browser information
207
public static Command<GetVersionResponse> getVersion();
208
public static Command<GetBrowserCommandLineResponse> getBrowserCommandLine();
209
210
// Window management
211
public static Command<GetWindowBoundsResponse> getWindowBounds(WindowId windowId);
212
public static Command<Void> setWindowBounds(WindowId windowId, Bounds bounds);
213
214
// Permission management
215
public static Command<Void> grantPermissions(List<PermissionType> permissions, Optional<String> origin);
216
public static Command<Void> resetPermissions();
217
```
218
219
#### Emulation Domain
220
221
Device and environment emulation capabilities.
222
223
```java { .api }
224
import org.openqa.selenium.devtools.v105.emulation.Emulation;
225
import org.openqa.selenium.devtools.v105.emulation.model.*;
226
227
// Device emulation
228
public static Command<Void> setDeviceMetricsOverride(int width, int height, Number deviceScaleFactor, Boolean mobile);
229
public static Command<Void> clearDeviceMetricsOverride();
230
231
// Geolocation emulation
232
public static Command<Void> setGeolocationOverride(Optional<Number> latitude, Optional<Number> longitude, Optional<Number> accuracy);
233
public static Command<Void> clearGeolocationOverride();
234
235
// Media emulation
236
public static Command<Void> setEmulatedMedia(Optional<String> media, Optional<List<MediaFeature>> features);
237
238
// Timezone emulation
239
public static Command<Void> setTimezoneOverride(String timezoneId);
240
```
241
242
### Security and Storage Domains
243
244
Domains for security monitoring and storage management.
245
246
#### Security Domain
247
248
Security state monitoring and certificate handling.
249
250
```java { .api }
251
import org.openqa.selenium.devtools.v105.security.Security;
252
import org.openqa.selenium.devtools.v105.security.model.*;
253
254
// Enable security monitoring
255
public static Command<Void> enable();
256
public static Command<Void> disable();
257
258
// Certificate handling
259
public static Command<Void> handleCertificateError(int eventId, CertificateErrorAction action);
260
public static Command<Void> setOverrideCertificateErrors(Boolean override);
261
262
// Security events
263
public static Event<SecurityStateChanged> securityStateChanged();
264
public static Event<CertificateError> certificateError();
265
```
266
267
#### Storage Domain
268
269
Browser storage management (localStorage, sessionStorage, IndexedDB, etc.).
270
271
```java { .api }
272
import org.openqa.selenium.devtools.v105.storage.Storage;
273
import org.openqa.selenium.devtools.v105.storage.model.*;
274
275
// Storage clearing
276
public static Command<Void> clearDataForOrigin(String origin, String storageTypes);
277
278
// Cache storage
279
public static Command<GetCacheStorageResponse> getCacheStorage(String origin);
280
public static Command<Void> deleteCacheStorage(String origin, String cacheName);
281
282
// Storage events
283
public static Event<CacheStorageContentUpdated> cacheStorageContentUpdated();
284
public static Event<CacheStorageListUpdated> cacheStorageListUpdated();
285
```
286
287
### Advanced and Experimental Domains
288
289
Additional domains for specialized use cases (marked as experimental).
290
291
**Available Experimental Domains:**
292
293
- **CSS** - Style manipulation and inspection
294
- **DOM** - Document Object Model access
295
- **Accessibility** - Accessibility tree inspection
296
- **Animation** - CSS/Web Animation control
297
- **Audits** - Lighthouse-style auditing
298
- **Performance** - Performance metrics collection
299
- **Tracing** - Chrome tracing integration
300
- **ServiceWorker** - Service worker lifecycle
301
- **IndexedDB** - IndexedDB inspection and control
302
- **WebAuthn** - WebAuthentication API testing
303
- **Input** - Input event simulation
304
- **IO** - Stream input/output operations
305
306
## Direct CDP Usage Patterns
307
308
### Basic CDP Command Pattern
309
310
```java
311
// Enable domain
312
devTools.send(Runtime.enable());
313
314
// Send command
315
EvaluateResponse response = devTools.send(Runtime.evaluate("window.location.href"));
316
317
// Process result
318
if (response.getExceptionDetails().isPresent()) {
319
System.err.println("JavaScript error: " + response.getExceptionDetails().get().getText());
320
} else {
321
System.out.println("Result: " + response.getResult().getValue());
322
}
323
324
// Clean up
325
devTools.send(Runtime.disable());
326
```
327
328
### Event Subscription Pattern
329
330
```java
331
// Subscribe to events before enabling domain
332
Runtime.consoleAPICalled().addListener(consoleEvent -> {
333
System.out.println("Console " + consoleEvent.getType() + ": " +
334
consoleEvent.getArgs().stream()
335
.map(arg -> arg.getValue().orElse(arg.getDescription().orElse("undefined")))
336
.collect(Collectors.joining(" ")));
337
});
338
339
// Enable domain to start receiving events
340
devTools.send(Runtime.enable());
341
342
// Events will now be delivered to the listener
343
```
344
345
### Multi-Domain Coordination
346
347
```java
348
public class AdvancedBrowserControl {
349
350
public void setupComprehensiveMonitoring(DevTools devTools) {
351
// Enable multiple domains
352
devTools.send(Runtime.enable());
353
devTools.send(Network.enable());
354
devTools.send(Page.enable());
355
devTools.send(Security.enable());
356
357
// Set up cross-domain event handling
358
setupEventHandlers();
359
360
// Configure browser state
361
devTools.send(Network.setCacheDisabled(true));
362
devTools.send(Emulation.setUserAgentOverride("Test-Bot/1.0", Optional.empty(), Optional.empty()));
363
}
364
365
private void setupEventHandlers() {
366
// Network monitoring
367
Network.requestWillBeSent().addListener(this::logRequest);
368
Network.responseReceived().addListener(this::logResponse);
369
370
// Page lifecycle
371
Page.frameNavigated().addListener(this::handleNavigation);
372
Page.loadEventFired().addListener(this::handlePageLoad);
373
374
// Runtime monitoring
375
Runtime.consoleAPICalled().addListener(this::handleConsole);
376
Runtime.exceptionThrown().addListener(this::handleException);
377
378
// Security monitoring
379
Security.securityStateChanged().addListener(this::handleSecurityChange);
380
}
381
}
382
```
383
384
## Types
385
386
### Command and Event Base Types
387
388
```java { .api }
389
// Base command type
390
public class Command<T> {
391
String getMethod();
392
Map<String, Object> getParams();
393
}
394
395
// Base event type
396
public class Event<T> {
397
String getMethod();
398
Function<JsonInput, T> getMapper();
399
}
400
401
// DevTools session
402
public interface DevTools {
403
<T> T send(Command<T> command);
404
<T> void addListener(Event<T> event, Consumer<T> listener);
405
void createSession();
406
void close();
407
}
408
```
409
410
### Common Response Types
411
412
```java { .api }
413
// Evaluation response
414
public class EvaluateResponse {
415
RemoteObject getResult();
416
Optional<ExceptionDetails> getExceptionDetails();
417
}
418
419
// Remote object representation
420
public class RemoteObject {
421
RemoteObject.Type getType();
422
Optional<Object> getValue();
423
Optional<String> getDescription();
424
Optional<RemoteObjectId> getObjectId();
425
}
426
427
// Exception details
428
public class ExceptionDetails {
429
String getText();
430
int getLineNumber();
431
int getColumnNumber();
432
Optional<String> getUrl();
433
Optional<StackTrace> getStackTrace();
434
}
435
```