Chrome DevTools Protocol (CDP) bindings for Selenium WebDriver version 138
npx @tessl/cli install tessl/maven-org-seleniumhq-selenium--selenium-devtools-v138@4.35.00
# Selenium DevTools v138
1
2
Chrome DevTools Protocol (CDP) bindings for Selenium WebDriver version 138, enabling low-level browser interaction and automation beyond standard WebDriver capabilities. This package provides Java bindings that allow developers to interact with Chrome/Chromium browsers through the DevTools interface for advanced debugging, monitoring, and automation scenarios.
3
4
## Package Information
5
6
- **Package Name**: org.seleniumhq.selenium:selenium-devtools-v138
7
- **Package Type**: Maven
8
- **Language**: Java
9
- **Version**: 4.35.0
10
- **Installation**: Add to your Maven dependencies:
11
12
```xml
13
<dependency>
14
<groupId>org.seleniumhq.selenium</groupId>
15
<artifactId>selenium-devtools-v138</artifactId>
16
<version>4.35.0</version>
17
</dependency>
18
```
19
20
## Core Imports
21
22
```java
23
import org.openqa.selenium.devtools.v138.*;
24
import org.openqa.selenium.devtools.DevTools;
25
import org.openqa.selenium.chrome.ChromeDriver;
26
```
27
28
For specific domains:
29
30
```java
31
import org.openqa.selenium.devtools.v138.v138Domains;
32
import org.openqa.selenium.devtools.v138.v138Events;
33
import org.openqa.selenium.devtools.v138.v138Javascript;
34
import org.openqa.selenium.devtools.v138.v138Network;
35
import org.openqa.selenium.devtools.v138.v138Log;
36
import org.openqa.selenium.devtools.v138.v138Target;
37
```
38
39
For public API usage:
40
41
```java
42
import java.util.function.Consumer;
43
import java.util.function.Predicate;
44
import java.util.function.Supplier;
45
import org.openqa.selenium.Credentials;
46
```
47
48
## Basic Usage
49
50
```java
51
import org.openqa.selenium.chrome.ChromeDriver;
52
import org.openqa.selenium.devtools.DevTools;
53
import org.openqa.selenium.devtools.v138.v138Domains;
54
55
// Create Chrome driver and get DevTools
56
ChromeDriver driver = new ChromeDriver();
57
DevTools devTools = driver.getDevTools();
58
59
// Create and use v138 domains
60
devTools.createSession();
61
v138Domains domains = new v138Domains(devTools);
62
63
// Enable console logging
64
devTools.send(domains.log().enable());
65
66
// Listen for console events (using Events domain)
67
domains.events().addConsoleListener(console ->
68
System.out.println("Console " + console.getType() + ": " +
69
console.getArgs().get(0)));
70
71
// Navigate to a page
72
driver.get("https://example.com");
73
74
// Clean up
75
devTools.close();
76
driver.quit();
77
```
78
79
## Architecture
80
81
The v138 package implements Chrome DevTools Protocol version 138 through a layered architecture:
82
83
- **Service Registration**: `v138CdpInfo` provides automatic version discovery via Java ServiceLoader
84
- **Domain Aggregation**: `v138Domains` serves as the main entry point, providing access to all CDP domains
85
- **Specialized Domains**: Individual domain implementations (`v138Network`, `v138Javascript`, etc.) wrap generated CDP classes
86
- **Protocol Abstraction**: All classes implement idealized interfaces from `org.openqa.selenium.devtools.idealized.*`
87
- **Version Compatibility**: Designed for Chrome version 138 with backward/forward compatibility within a 5-version range
88
89
## Capabilities
90
91
### Domain Management
92
93
Main entry point providing access to all Chrome DevTools Protocol domains. Essential for initializing and coordinating CDP functionality.
94
95
```java { .api }
96
public class v138Domains implements Domains {
97
public v138Domains(DevTools devtools);
98
public Events<?, ?> events();
99
public Javascript<?, ?> javascript();
100
public Network<?, ?> network();
101
public Target target();
102
public Log log();
103
}
104
```
105
106
[Domain Management](./domain-management.md)
107
108
### Runtime Events and Console
109
110
Runtime events handling and console monitoring capabilities. Enables capturing JavaScript exceptions, console messages, and runtime diagnostics.
111
112
```java { .api }
113
public class v138Events extends Events<ConsoleAPICalled, ExceptionThrown> {
114
public v138Events(DevTools devtools);
115
protected Event<ConsoleAPICalled> consoleEvent();
116
protected Event<ExceptionThrown> exceptionThrownEvent();
117
protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event);
118
protected JavascriptException toJsException(ExceptionThrown event);
119
}
120
```
121
122
[Runtime Events](./runtime-events.md)
123
124
### JavaScript Execution and Binding
125
126
JavaScript execution environment management and bidirectional communication setup. Provides script injection, binding management, and page-level script control.
127
128
```java { .api }
129
public class v138Javascript extends Javascript<ScriptIdentifier, BindingCalled> {
130
public v138Javascript(DevTools devtools);
131
protected Command<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String script);
132
protected Command<Void> removeScriptToEvaluateOnNewDocument(ScriptIdentifier id);
133
protected Command<Void> doAddJsBinding(String scriptName);
134
protected Command<Void> doRemoveJsBinding(String scriptName);
135
}
136
```
137
138
[JavaScript Integration](./javascript-integration.md)
139
140
### Network Monitoring and Interception
141
142
Network traffic monitoring, request/response interception, and authentication handling. Essential for API testing, performance monitoring, and request modification.
143
144
```java { .api }
145
public class v138Network extends Network<AuthRequired, RequestPaused> {
146
public v138Network(DevTools devTools);
147
protected Command<Void> setUserAgentOverride(UserAgent userAgent);
148
protected Command<Void> enableNetworkCaching();
149
protected Command<Void> disableNetworkCaching();
150
protected Event<AuthRequired> authRequiredEvent();
151
protected Event<RequestPaused> requestPausedEvent();
152
public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);
153
}
154
```
155
156
[Network Operations](./network-operations.md)
157
158
### Console Logging
159
160
Console log management and event streaming. Provides access to browser console output with level filtering and timestamp conversion.
161
162
```java { .api }
163
public class v138Log implements org.openqa.selenium.devtools.idealized.log.Log {
164
public Command<Void> enable();
165
public Command<Void> clear();
166
public Event<LogEntry> entryAdded();
167
}
168
```
169
170
[Console Logging](./console-logging.md)
171
172
### Target Management
173
174
Browser target (tab/window) management and session control. Enables working with multiple browser contexts and coordinating cross-target operations.
175
176
```java { .api }
177
public class v138Target implements org.openqa.selenium.devtools.idealized.target.Target {
178
public Command<List<TargetInfo>> getTargets();
179
public Command<SessionID> attachToTarget(TargetID targetId);
180
public Command<Void> detachFromTarget(Optional<SessionID> sessionId, Optional<TargetID> targetId);
181
public Command<Void> setAutoAttach();
182
public Event<TargetID> detached();
183
}
184
```
185
186
[Target Management](./target-management.md)
187
188
### Version Registration
189
190
Service registration for automatic CDP version discovery. Handles integration with Selenium's version selection mechanism.
191
192
```java { .api }
193
@AutoService(CdpInfo.class)
194
public class v138CdpInfo extends CdpInfo {
195
public v138CdpInfo();
196
}
197
```
198
199
[Version System](./version-system.md)
200
201
## Types
202
203
```java { .api }
204
// Core DevTools integration
205
interface Domains {
206
Events<?, ?> events();
207
Javascript<?, ?> javascript();
208
Network<?, ?> network();
209
Target target();
210
Log log();
211
}
212
213
// Command pattern for CDP operations
214
interface Command<T> {
215
String getMethod();
216
Map<String, Object> getParams();
217
}
218
219
// Event streaming for CDP notifications
220
interface Event<T> {
221
String getMethod();
222
Function<JsonInput, T> map();
223
}
224
225
// Network interception types
226
class UserAgent {
227
String userAgent();
228
String acceptLanguage();
229
String platform();
230
}
231
232
// Target management types
233
class TargetInfo {
234
TargetID getTargetId();
235
String getType();
236
String getTitle();
237
String getUrl();
238
Boolean getAttached();
239
Optional<TargetID> getOpenerId();
240
}
241
242
class SessionID {
243
String toString();
244
}
245
246
class TargetID {
247
String toString();
248
}
249
250
// Console and logging types
251
class ConsoleEvent {
252
String getType();
253
Instant getTimestamp();
254
List<Object> getArgs();
255
}
256
257
class LogEntry {
258
String getSource();
259
org.openqa.selenium.logging.LogEntry getEntry();
260
}
261
262
// Functional interfaces for API methods
263
@FunctionalInterface
264
interface Consumer<T> {
265
void accept(T t);
266
}
267
268
@FunctionalInterface
269
interface Predicate<T> {
270
boolean test(T t);
271
}
272
273
@FunctionalInterface
274
interface Supplier<T> {
275
T get();
276
}
277
278
@FunctionalInterface
279
interface Filter {
280
boolean test(HttpRequest request);
281
}
282
283
// Authentication types
284
class Credentials {
285
Credentials(String username, String password);
286
String getUsername();
287
String getPassword();
288
}
289
290
// Script management types
291
class ScriptId {
292
String toString(); // Unique identifier for pinned scripts
293
}
294
```