CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Chrome DevTools Protocol (CDP) client library for Chrome version 105, providing Java bindings for browser automation and debugging capabilities

Pending
Overview
Eval results
Files

network.mddocs/

Network Operations

Advanced network interception and monitoring capabilities for Chrome DevTools Protocol v105. Provides comprehensive control over network traffic including request/response modification, authentication handling, and traffic analysis.

Capabilities

Network Monitoring

Configure network monitoring to intercept and analyze HTTP traffic through high-level methods.

/**
 * Initialize network handler for monitoring and interception
 * @param devTools DevTools session instance
 */
public V105Network(DevTools devTools);

// Inherited methods from Network base class
/**
 * Disable network interception and reset to defaults
 */
public void disable();

/**
 * Set up request interception for authentication and filtering
 */
public void prepareToInterceptTraffic();

/**
 * Add filter for intercepting and modifying HTTP traffic
 * @param filter HTTP filter for request/response modification
 */
public void interceptTrafficWith(Filter filter);

// Protected methods implemented by V105Network
protected Command<Void> setUserAgentOverride(UserAgent userAgent);
protected Command<Void> enableNetworkCaching();
protected Command<Void> disableNetworkCaching();
protected Command<Void> enableFetchForAllPatterns();
protected Command<Void> disableFetch();

Usage Examples:

import org.openqa.selenium.devtools.v105.V105Network;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.remote.http.Filter;

// Initialize network monitoring
V105Network network = new V105Network(devTools);

// Set up request interception
network.prepareToInterceptTraffic();

// Add custom filter for modifying requests
Filter customFilter = next -> req -> {
    // Add custom header to all requests
    req.addHeader("X-Test-Mode", "true");
    return next.execute(req);
};
network.interceptTrafficWith(customFilter);

// Clean up when done
network.disable();

User Agent Override

Override the browser's user agent string for testing different browsers or devices.

/**
 * Set user agent override with full configuration (protected method)
 * @param userAgent User agent configuration including platform and language
 * @return Command to set user agent override
 */
protected Command<Void> setUserAgentOverride(UserAgent userAgent);

/**
 * User agent configuration (inherited from Network base class)
 */
public static class UserAgent {
    String userAgent();
    String acceptLanguage();
    String platform();
}

Usage Examples:

// Override user agent for mobile testing - use CDP Network domain directly
devTools.send(org.openqa.selenium.devtools.v105.network.Network.setUserAgentOverride(
    "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15",
    Optional.of("en-US,en;q=0.9"), 
    Optional.of("iOS"),
    Optional.empty()
));

Authentication Handling

Handle HTTP authentication challenges automatically.

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

/**
 * Extract URI from authentication challenge
 * @param authRequired Authentication challenge event
 * @return Origin URI requiring authentication
 */
protected String getUriFrom(AuthRequired authRequired);

/**
 * Continue with provided credentials
 * @param authRequired Authentication challenge event
 * @param credentials Username and password
 * @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 Examples:

import org.openqa.selenium.UsernameAndPassword;

// Set up authentication listener
network.authRequiredEvent().addListener(authRequired -> {
    String origin = network.getUriFrom(authRequired);
    
    if (origin.contains("secure-api.example.com")) {
        // Provide credentials for specific domain
        UsernameAndPassword creds = new UsernameAndPassword("user", "pass");
        devTools.send(network.continueWithAuth(authRequired, creds));
    } else {
        // Cancel authentication for other domains
        devTools.send(network.cancelAuth(authRequired));
    }
});

Request and Response Interception

Intercept, modify, and fulfill HTTP requests and responses.

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

/**
 * Create Selenium HTTP messages from intercepted request
 * @param pausedReq Paused request event data
 * @return Either HTTP request or response object
 */
public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);

/**
 * Extract request ID from paused request
 * @param pausedReq Paused request event
 * @return String request identifier
 */
protected String getRequestId(RequestPaused pausedReq);

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

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

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

Usage Examples:

import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.internal.Either;

// Set up request interception
network.requestPausedEvent().addListener(pausedRequest -> {
    Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedRequest);
    
    if (message.isLeft()) {
        // Handle intercepted request
        HttpRequest request = message.left();
        
        if (request.getUri().contains("/api/data")) {
            // Modify request headers
            request.addHeader("X-Test-Mode", "true");
            devTools.send(network.continueRequest(pausedRequest, request));
        } else {
            // Continue without modification
            devTools.send(network.continueWithoutModification(pausedRequest));
        }
    } else {
        // Handle intercepted response  
        HttpResponse response = message.right();
        
        if (response.getStatus() == 404) {
            // Fulfill with custom response
            HttpResponse customResponse = new HttpResponse()
                .setStatus(200)
                .setContent("Custom content".getBytes());
            devTools.send(network.fulfillRequest(pausedRequest, customResponse));
        }
    }
});

Types

Core Network Types

// Network domain implementation
public class V105Network extends Network<AuthRequired, RequestPaused> {
    public V105Network(DevTools devTools);
}

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

Authentication Types

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

// Authentication challenge details
public class AuthChallenge {
    String getOrigin();
    String getScheme();
    String getRealm();
}

// Username and password credentials
public class UsernameAndPassword {
    UsernameAndPassword(String username, String password);
    String username();
    String password();
}

Request Interception Types

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

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

// HTTP header entry
public class HeaderEntry {
    HeaderEntry(String name, String value);
    String getName();
    String getValue();
}

// Request identifier
public class RequestId {
    RequestId(String id);
    String toString();
}

Install with Tessl CLI

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

docs

cdp-domains.md

events.md

index.md

javascript.md

logging.md

network.md

targets.md

tile.json