Chrome DevTools Protocol bindings for Selenium WebDriver version 111
—
Network domain implementation for HTTP request/response interception, authentication handling, and caching control. Provides comprehensive network monitoring capabilities for automated testing, API mocking, and performance analysis.
Enable and disable request/response interception for all network patterns, allowing modification of HTTP traffic in real-time.
public Command<Void> enableFetchForAllPatterns();
public Command<Void> disableFetch();Usage example:
v111Network network = domains.network();
// Enable interception for all requests
devTools.send(network.enableFetchForAllPatterns());
// Listen for paused requests
devTools.addListener(network.requestPausedEvent(), pausedRequest -> {
// Handle intercepted request
if (pausedRequest.getRequest().getUrl().contains("/api/")) {
// Modify API requests
HttpRequest modifiedRequest = createModifiedRequest(pausedRequest);
devTools.send(network.continueRequest(pausedRequest, modifiedRequest));
} else {
// Continue without modification
devTools.send(network.continueWithoutModification(pausedRequest));
}
});Handle HTTP authentication challenges with credential provision or cancellation.
public Event<AuthRequired> authRequiredEvent();
public String getUriFrom(AuthRequired authRequired);
public Command<Void> continueWithAuth(AuthRequired authRequired, UsernameAndPassword credentials);
public Command<Void> cancelAuth(AuthRequired authRequired);Usage example:
// Listen for authentication challenges
devTools.addListener(network.authRequiredEvent(), authRequired -> {
String uri = network.getUriFrom(authRequired);
if (uri.contains("secure-api.example.com")) {
// Provide credentials
UsernameAndPassword creds = new UsernameAndPassword("user", "pass");
devTools.send(network.continueWithAuth(authRequired, creds));
} else {
// Cancel authentication
devTools.send(network.cancelAuth(authRequired));
}
});Handle intercepted requests and responses with modification capabilities.
public Event<RequestPaused> requestPausedEvent();
public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);
public String getRequestId(RequestPaused pausedReq);
public Command<Void> continueWithoutModification(RequestPaused pausedRequest);
public Command<Void> continueRequest(RequestPaused pausedReq, HttpRequest req);
public Command<Void> fulfillRequest(RequestPaused pausedReq, HttpResponse res);Usage example:
devTools.addListener(network.requestPausedEvent(), pausedRequest -> {
Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedRequest);
if (message.isLeft()) {
// Handle request
HttpRequest request = message.left();
if (request.getUri().contains("/block-me")) {
// Block request with 404 response
HttpResponse blockedResponse = new HttpResponse()
.setStatus(404)
.setContent(Contents.utf8String("Blocked"));
devTools.send(network.fulfillRequest(pausedRequest, blockedResponse));
} else {
devTools.send(network.continueWithoutModification(pausedRequest));
}
} else {
// Handle response
HttpResponse response = message.right();
devTools.send(network.continueWithoutModification(pausedRequest));
}
});Override browser user agent string with custom values.
public Command<Void> setUserAgentOverride(UserAgent userAgent);Usage example:
UserAgent customUA = new UserAgent(
"CustomBot/1.0 (Testing)",
"en-US,en;q=0.9",
"CustomPlatform"
);
devTools.send(network.setUserAgentOverride(customUA));Enable or disable network caching for testing scenarios.
public Command<Void> enableNetworkCaching();
public Command<Void> disableNetworkCaching();Usage example:
// Disable caching for testing
devTools.send(network.disableNetworkCaching());
// Re-enable caching
devTools.send(network.enableNetworkCaching());class AuthRequired {
public AuthChallenge getAuthChallenge();
public RequestId getRequestId();
}
class RequestPaused {
public RequestId getRequestId();
public Request getRequest();
public Optional<Integer> getResponseStatusCode();
public Optional<String> getResponseErrorReason();
public Optional<List<HeaderEntry>> getResponseHeaders();
}class UserAgent {
public UserAgent(String userAgent, String acceptLanguage, String platform);
public String userAgent();
public String acceptLanguage();
public String platform();
}
class UsernameAndPassword {
public UsernameAndPassword(String username, String password);
public String username();
public String password();
}class HttpRequest {
public String getMethod();
public String getUri();
public Iterable<String> getHeaderNames();
public Iterable<String> getHeaders(String name);
public Supplier<InputStream> getContent();
}
class HttpResponse {
public int getStatus();
public Iterable<String> getHeaderNames();
public Iterable<String> getHeaders(String name);
public Supplier<InputStream> getContent();
}Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-devtools-v111