CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-devtools-v110

Chrome DevTools Protocol (CDP) bindings for Java - version 110, enabling advanced browser automation features like network interception, console event handling, JavaScript execution, and target management.

Pending
Overview
Eval results
Files

network.mddocs/

Network Operations

Advanced network functionality for request/response interception, authentication handling, user agent modification, and comprehensive traffic monitoring using Chrome DevTools Protocol v110.

Capabilities

Network Domain Wrapper

High-level wrapper for CDP network functionality providing type-safe access to network monitoring and interception.

/**
 * Network domain wrapper for CDP v110 network operations
 */
public class v110Network extends Network<AuthRequired, RequestPaused> {
    /**
     * Initialize network domain with DevTools session
     * @param devTools Active DevTools session
     */
    public v110Network(DevTools devTools);
}

User Agent Management

Override the browser's user agent string for all network requests.

/**
 * Set custom user agent for network requests
 * @param userAgent User agent configuration
 * @return Command to execute
 */
protected Command<Void> setUserAgentOverride(UserAgent userAgent);

/**
 * User agent configuration
 */
public static class UserAgent {
    private final String userAgent;
    private final String acceptLanguage;
    private final String platform;
    
    public UserAgent(String userAgent);
    public UserAgent(String userAgent, String acceptLanguage, String platform);
    
    public String userAgent();
    public String acceptLanguage(); 
    public String platform();
}

Usage Example:

import org.openqa.selenium.devtools.v110.v110Network;
import org.openqa.selenium.devtools.idealized.Network.UserAgent;

v110Network network = new v110Network(devTools);
UserAgent customAgent = new UserAgent(
    "Mozilla/5.0 (Custom Browser) WebKit/537.36",
    "en-US,en;q=0.9",
    "Custom Platform"
);

devTools.send(network.setUserAgentOverride(customAgent));

Network Caching Control

Enable or disable browser network caching for testing and debugging purposes.

/**
 * Enable network caching
 * @return Command to execute
 */
protected Command<Void> enableNetworkCaching();

/**
 * Disable network caching  
 * @return Command to execute
 */
protected Command<Void> disableNetworkCaching();

Request Interception

Intercept and modify HTTP requests and responses using the Fetch domain.

/**
 * Enable fetch domain for all request patterns
 * @return Command to enable request interception
 */
protected Command<Void> enableFetchForAllPatterns();

/**
 * Disable fetch domain and request interception
 * @return Command to disable interception
 */
protected Command<Void> disableFetch();

/**
 * Get request paused events for interception
 * @return Event stream for paused requests
 */
public Event<RequestPaused> requestPausedEvent();

Authentication Handling

Handle HTTP authentication challenges automatically.

/**
 * Get authentication required events
 * @return Event stream for auth challenges
 */
protected Event<AuthRequired> authRequiredEvent();

/**
 * Continue with provided credentials
 * @param authRequired Auth challenge event
 * @param credentials Username and password
 * @return Command to provide credentials
 */
protected Command<Void> continueWithAuth(AuthRequired authRequired, UsernameAndPassword credentials);

/**
 * Cancel authentication challenge
 * @param authRequired Auth challenge event  
 * @return Command to cancel auth
 */
protected Command<Void> cancelAuth(AuthRequired authRequired);

Usage Example:

import org.openqa.selenium.UsernameAndPassword;
import org.openqa.selenium.devtools.v110.fetch.model.AuthRequired;

// Add authentication handler
network.addAuthHandler(
    uri -> uri.contains("secure-api.com"),
    new UsernameAndPassword("api-user", "secret-key")
);

// Or handle auth events manually
devTools.addListener(network.authRequiredEvent(), authRequired -> {
    String origin = network.getUriFrom(authRequired);
    if (origin.contains("trusted-site.com")) {
        devTools.send(network.continueWithAuth(
            authRequired, 
            new UsernameAndPassword("username", "password")
        ));
    } else {
        devTools.send(network.cancelAuth(authRequired));
    }
});

Request and Response Processing

Process intercepted requests and responses with full control over headers, body, and status.

/**
 * Continue request without modification
 * @param pausedRequest Intercepted request
 * @return Command to continue
 */
protected Command<Void> continueWithoutModification(RequestPaused pausedRequest);

/**
 * Continue with modified request
 * @param pausedReq Original intercepted request
 * @param req Modified request to send
 * @return Command to continue with modifications
 */
protected Command<Void> continueRequest(RequestPaused pausedReq, HttpRequest req);

/**
 * Fulfill request with custom response
 * @param pausedReq Intercepted request
 * @param res Custom response to return
 * @return Command to fulfill with response
 */
protected Command<Void> fulfillRequest(RequestPaused pausedReq, HttpResponse res);

/**
 * Create Selenium HTTP message from CDP request/response
 * @param pausedReq CDP request paused event
 * @return Either HTTP request or response
 */
public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);

CDP Domain Classes

Fetch Domain

Direct access to CDP Fetch domain for advanced request interception.

import org.openqa.selenium.devtools.v110.fetch.Fetch;
import org.openqa.selenium.devtools.v110.fetch.model.*;

/**
 * Enable fetch domain with request patterns
 */
public static Command<Void> enable(
    Optional<List<RequestPattern>> patterns,
    Optional<Boolean> handleAuthRequests
);

/**
 * Continue intercepted request
 */
public static Command<Void> continueRequest(
    RequestId requestId,
    Optional<String> url,
    Optional<String> method, 
    Optional<String> postData,
    Optional<List<HeaderEntry>> headers,
    Optional<Boolean> interceptResponse
);

/**
 * Fulfill request with response
 */
public static Command<Void> fulfillRequest(
    RequestId requestId,
    Integer responseCode,
    Optional<List<HeaderEntry>> responseHeaders,
    Optional<String> binaryResponseHeaders,
    Optional<String> body,
    Optional<String> responsePhrase
);

Network Domain

Direct access to CDP Network domain for low-level network operations.

import org.openqa.selenium.devtools.v110.network.Network;

/**
 * Enable network domain
 */
public static Command<Void> enable(
    Optional<Integer> maxTotalBufferSize,
    Optional<Integer> maxResourceBufferSize, 
    Optional<Integer> maxPostDataSize
);

/**
 * Set user agent override
 */
public static Command<Void> setUserAgentOverride(
    String userAgent,
    Optional<String> acceptLanguage,
    Optional<String> platform,
    Optional<UserAgentMetadata> userAgentMetadata
);

/**
 * Control network cache
 */
public static Command<Void> setCacheDisabled(Boolean cacheDisabled);

Model Classes

Request and Response Models

import org.openqa.selenium.devtools.v110.fetch.model.*;
import org.openqa.selenium.devtools.v110.network.model.*;

/**
 * HTTP request information
 */
public class Request {
    String getUrl();
    String getMethod();
    Map<String, String> getHeaders();
    Optional<String> getPostData();
}

/**
 * Request interception pattern
 */
public class RequestPattern {
    Optional<String> getUrlPattern();
    Optional<ResourceType> getResourceType();
    Optional<RequestStage> getRequestStage();
}

/**
 * Authentication challenge
 */
public class AuthRequired {
    RequestId getRequestId();
    AuthChallenge getAuthChallenge();
}

/**
 * Paused request for interception
 */  
public class RequestPaused {
    RequestId getRequestId();  
    Request getRequest();
    Optional<Integer> getResponseStatusCode();
    Optional<List<HeaderEntry>> getResponseHeaders();
}

/**
 * HTTP header entry
 */
public class HeaderEntry {
    String getName();
    String getValue();
}

Error Handling

Network operations may encounter various error conditions:

import org.openqa.selenium.devtools.DevToolsException;

// Handle network command failures
try {
    devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
} catch (DevToolsException e) {
    System.err.println("Failed to enable network domain: " + e.getMessage());
}

// Handle request interception errors
devTools.addListener(network.requestPausedEvent(), pausedRequest -> {
    try {
        // Process request
        devTools.send(network.continueWithoutModification(pausedRequest));
    } catch (DevToolsException e) {
        System.err.println("Failed to continue request: " + e.getMessage());
    }
});

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-devtools-v110

docs

events.md

index.md

javascript.md

logging.md

network.md

target.md

tile.json