Java bindings for Chrome DevTools Protocol v133, enabling advanced browser automation capabilities through Selenium WebDriver.
—
The v133Network class provides comprehensive network monitoring and interception capabilities, enabling developers to monitor network activity, intercept requests and responses, handle authentication challenges, and modify network behavior.
Main network control class that extends the base Network functionality with v133-specific implementations.
/**
* v133-specific network monitoring and interception implementation
* Extends Network<AuthRequired, RequestPaused> for type-safe network operations
*/
public class v133Network extends Network<AuthRequired, RequestPaused> {
private static final Logger LOG = Logger.getLogger(v133Network.class.getName());
/**
* Creates a new v133Network instance
* @param devTools DevTools instance for communication with browser
*/
public v133Network(DevTools devTools);
}Control and override the browser's user agent string and related headers.
/**
* Set user agent override for network requests
* @param userAgent UserAgent configuration with user agent string, accept language, and platform
* @return Command to set user agent override
*/
protected Command<Void> setUserAgentOverride(UserAgent userAgent);Usage Example:
import org.openqa.selenium.devtools.idealized.Network.UserAgent;
v133Network network = new v133Network(devTools);
// Set custom user agent
UserAgent customUA = new UserAgent(
"Custom-Browser/1.0 (Compatible)",
"en-US,en;q=0.9",
"Custom Platform"
);
devTools.send(network.setUserAgentOverride(customUA));Enable or disable network caching to control browser cache behavior during testing.
/**
* Enable network caching in the browser
* @return Command to enable network caching
*/
protected Command<Void> enableNetworkCaching();
/**
* Disable network caching in the browser
* @return Command to disable network caching
*/
protected Command<Void> disableNetworkCaching();Enable and disable network request interception for comprehensive request/response monitoring and modification.
/**
* Enable fetch interception for all request patterns
* Enables interception of both REQUEST and RESPONSE stages
* @return Command to enable fetch interception
*/
protected Command<Void> enableFetchForAllPatterns();
/**
* Disable fetch interception to stop monitoring network requests
* @return Command to disable fetch interception
*/
protected Command<Void> disableFetch();
/**
* Get the request paused event for intercepted requests
* @return Event for monitoring paused requests
*/
public Event<RequestPaused> requestPausedEvent();Usage Example:
import org.openqa.selenium.devtools.v133.fetch.model.RequestPaused;
// Enable request interception
devTools.send(network.enableFetchForAllPatterns());
// Listen for intercepted requests
devTools.addListener(network.requestPausedEvent(), (RequestPaused pausedReq) -> {
String requestId = network.getRequestId(pausedReq);
System.out.println("Intercepted request: " + requestId);
// Continue without modification
devTools.send(network.continueWithoutModification(pausedReq));
});Handle HTTP authentication challenges with credential management.
/**
* Get the authentication required event for HTTP auth challenges
* @return Event for monitoring authentication challenges
*/
protected Event<AuthRequired> authRequiredEvent();
/**
* Get URI from authentication required event
* @param authRequired Authentication challenge event
* @return URI string that requires authentication
*/
protected String getUriFrom(AuthRequired authRequired);
/**
* Continue authentication with provided credentials
* @param authRequired Authentication challenge event
* @param credentials Username and password for authentication
* @return Command to provide authentication credentials
*/
protected Command<Void> continueWithAuth(AuthRequired authRequired, UsernameAndPassword credentials);
/**
* Cancel authentication challenge
* @param authRequired Authentication challenge event
* @return Command to cancel authentication
*/
protected Command<Void> cancelAuth(AuthRequired authRequired);Usage Example:
import org.openqa.selenium.UsernameAndPassword;
import org.openqa.selenium.devtools.v133.fetch.model.AuthRequired;
// Listen for authentication challenges
devTools.addListener(network.authRequiredEvent(), (AuthRequired authReq) -> {
String uri = network.getUriFrom(authReq);
System.out.println("Authentication required for: " + uri);
// Provide credentials
UsernameAndPassword credentials = new UsernameAndPassword("user", "pass");
devTools.send(network.continueWithAuth(authReq, credentials));
// Or cancel authentication
// devTools.send(network.cancelAuth(authReq));
});Create and process HTTP messages from intercepted network traffic.
/**
* Create Selenium HTTP messages from paused request
* @param pausedReq Intercepted request/response
* @return Either HttpRequest (for requests) or HttpResponse (for responses)
*/
public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);
/**
* Check if paused request has an error response
* @param pausedReq Intercepted request
* @return true if the request has an error response
*/
protected boolean hasErrorResponse(RequestPaused pausedReq);
/**
* Get unique request identifier from paused request
* @param pausedReq Intercepted request
* @return String request ID
*/
protected String getRequestId(RequestPaused pausedReq);Modify intercepted requests and provide custom responses.
/**
* Continue intercepted request without any modifications
* @param pausedRequest Intercepted request
* @return Command to continue request unchanged
*/
protected Command<Void> continueWithoutModification(RequestPaused pausedRequest);
/**
* Continue intercepted request with modifications
* @param pausedReq Intercepted request
* @param req Modified HttpRequest to send instead
* @return Command to continue with modified request
*/
protected Command<Void> continueRequest(RequestPaused pausedReq, HttpRequest req);
/**
* Fulfill intercepted request with custom response
* @param pausedReq Intercepted request
* @param res Custom HttpResponse to return
* @return Command to fulfill request with custom response
*/
protected Command<Void> fulfillRequest(RequestPaused pausedReq, HttpResponse res);Usage Example:
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.internal.Either;
// Process intercepted requests
devTools.addListener(network.requestPausedEvent(), (RequestPaused pausedReq) -> {
Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedReq);
if (message.isLeft()) {
// Handle request
HttpRequest request = message.left();
System.out.println("Request: " + request.getMethod() + " " + request.getUri());
// Modify request if needed
if (request.getUri().contains("/api/")) {
request.addHeader("X-Test-Header", "Modified by Selenium");
devTools.send(network.continueRequest(pausedReq, request));
} else {
devTools.send(network.continueWithoutModification(pausedReq));
}
} else {
// Handle response
HttpResponse response = message.right();
System.out.println("Response: " + response.getStatus());
// Continue with original response
devTools.send(network.continueWithoutModification(pausedReq));
}
});Represents an intercepted network request or response.
// From org.openqa.selenium.devtools.v133.fetch.model.RequestPaused
public class RequestPaused {
public RequestId getRequestId(); // Unique request identifier
public Request getRequest(); // Request details
public Optional<Integer> getResponseStatusCode(); // Response status code (if response)
public Optional<List<HeaderEntry>> getResponseHeaders(); // Response headers (if response)
public Optional<ErrorReason> getResponseErrorReason(); // Error reason (if failed)
}Represents an HTTP authentication challenge.
// From org.openqa.selenium.devtools.v133.fetch.model.AuthRequired
public class AuthRequired {
public RequestId getRequestId(); // Request requiring authentication
public AuthChallenge getAuthChallenge(); // Authentication challenge details
}
public class AuthChallenge {
public String getOrigin(); // Origin requiring authentication
public String getScheme(); // Authentication scheme (Basic, Digest, etc.)
public Optional<String> getRealm(); // Authentication realm
}// From org.openqa.selenium.devtools.v133.network.model.Request
public class Request {
public String getUrl(); // Request URL
public String getMethod(); // HTTP method
public Map<String, String> getHeaders(); // Request headers
public Optional<String> getPostData(); // POST data (if applicable)
}
// From org.openqa.selenium.devtools.v133.fetch.model.HeaderEntry
public class HeaderEntry {
public HeaderEntry(String name, String value);
public String getName(); // Header name
public String getValue(); // Header value
}Filter and selectively process network requests based on criteria:
devTools.addListener(network.requestPausedEvent(), (RequestPaused pausedReq) -> {
Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedReq);
if (message.isLeft()) {
HttpRequest request = message.left();
String url = request.getUri().toString();
// Filter by URL pattern
if (url.contains("/api/sensitive")) {
// Block sensitive requests
HttpResponse blockedResponse = new HttpResponse()
.setStatus(403)
.setContent(() -> new ByteArrayInputStream("Blocked".getBytes()));
devTools.send(network.fulfillRequest(pausedReq, blockedResponse));
} else if (url.contains("/api/")) {
// Modify API requests
request.addHeader("Authorization", "Bearer test-token");
devTools.send(network.continueRequest(pausedReq, request));
} else {
// Continue other requests unchanged
devTools.send(network.continueWithoutModification(pausedReq));
}
} else {
devTools.send(network.continueWithoutModification(pausedReq));
}
});Create mock responses for testing:
import java.io.ByteArrayInputStream;
devTools.addListener(network.requestPausedEvent(), (RequestPaused pausedReq) -> {
Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedReq);
if (message.isLeft()) {
HttpRequest request = message.left();
if (request.getUri().toString().contains("/api/mock")) {
// Create mock response
String mockData = "{\"status\":\"mocked\",\"data\":[1,2,3]}";
HttpResponse mockResponse = new HttpResponse()
.setStatus(200)
.addHeader("Content-Type", "application/json")
.setContent(() -> new ByteArrayInputStream(mockData.getBytes()));
devTools.send(network.fulfillRequest(pausedReq, mockResponse));
} else {
devTools.send(network.continueWithoutModification(pausedReq));
}
} else {
devTools.send(network.continueWithoutModification(pausedReq));
}
});Network operations include comprehensive error handling for:
Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-devtools-v133