CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Chrome DevTools Protocol version 129 bindings for Selenium WebDriver.

Pending
Overview
Eval results
Files

network.mddocs/

Network Operations

The v129Network class provides comprehensive network interception and monitoring capabilities through the Chrome DevTools Protocol. It enables request/response manipulation, authentication handling, user agent overrides, and traffic analysis.

Capabilities

Network Domain

Core network domain providing request/response interception and monitoring.

/**
 * Network domain providing request/response interception and monitoring
 * @param devTools - DevTools instance for protocol communication
 */
public class v129Network extends Network<AuthRequired, RequestPaused> {
    public v129Network(DevTools devTools);
    
    /** Event fired when a request is paused for interception */
    public Event<RequestPaused> requestPausedEvent();
    
    /** Converts paused request to HttpRequest or HttpResponse */
    public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);
}

User Agent Override

Set custom user agent strings for network requests.

/**
 * Sets user agent override for all network requests
 * @param userAgent - UserAgent object containing user agent string and optional properties
 * @return Command to execute the user agent override
 */
protected Command<Void> setUserAgentOverride(UserAgent userAgent);

Network Caching Control

Enable or disable network caching for requests.

/**
 * Enables network caching for requests
 * @return Command to enable network caching
 */
protected Command<Void> enableNetworkCaching();

/**
 * Disables network caching for requests
 * @return Command to disable network caching
 */
protected Command<Void> disableNetworkCaching();

Request Interception

Enable fetch interception to modify requests and responses.

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

/**
 * Disables fetch interception
 * @return Command to disable fetch interception
 */
protected Command<Void> disableFetch();

Authentication Handling

Handle HTTP authentication challenges.

/**
 * Event fired when authentication is required
 * @return Event for authentication required notifications
 */
protected Event<AuthRequired> authRequiredEvent();

/**
 * Extracts URI from authentication required event
 * @param authRequired - Authentication required event
 * @return URI string requiring authentication
 */
protected String getUriFrom(AuthRequired authRequired);

/**
 * Continues request with provided authentication credentials
 * @param authRequired - Authentication required event
 * @param credentials - Username and password credentials
 * @return Command to continue with authentication
 */
protected Command<Void> continueWithAuth(AuthRequired authRequired, UsernameAndPassword credentials);

/**
 * Cancels authentication for the request
 * @param authRequired - Authentication required event
 * @return Command to cancel authentication
 */
protected Command<Void> cancelAuth(AuthRequired authRequired);

Request Management

Manage paused requests during interception.

/**
 * Checks if paused request has an error response
 * @param pausedReq - Paused request event
 * @return true if request has error response
 */
protected boolean hasErrorResponse(RequestPaused pausedReq);

/**
 * Gets request ID from paused request
 * @param pausedReq - Paused request event
 * @return Request ID string
 */
protected String getRequestId(RequestPaused pausedReq);

/**
 * Continues request without modification
 * @param pausedRequest - Paused request event
 * @return Command to continue request unmodified
 */
protected Command<Void> continueWithoutModification(RequestPaused pausedRequest);

/**
 * Continues request with modifications
 * @param pausedReq - Paused request event
 * @param req - Modified HttpRequest
 * @return Command to continue with modified request
 */
protected Command<Void> continueRequest(RequestPaused pausedReq, HttpRequest req);

/**
 * Fulfills request with custom response
 * @param pausedReq - Paused request event
 * @param res - HttpResponse to fulfill request with
 * @return Command to fulfill request with response
 */
protected Command<Void> fulfillRequest(RequestPaused pausedReq, HttpResponse res);

Usage Examples:

import org.openqa.selenium.devtools.v129.v129Network;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.UsernameAndPassword;

// Create network domain
DevTools devTools = driver.getDevTools();
v129Network network = new v129Network(devTools);

// Enable request interception
devTools.send(network.enableFetchForAllPatterns());

// Listen for paused requests
devTools.addListener(network.requestPausedEvent(), pausedReq -> {
    if (network.hasErrorResponse(pausedReq)) {
        // Handle error response
        return;
    }
    
    // Continue request without modification
    devTools.send(network.continueWithoutModification(pausedReq));
});

// Handle authentication
devTools.addListener(network.authRequiredEvent(), authReq -> {
    String uri = network.getUriFrom(authReq);
    if (uri.contains("secure-site.com")) {
        // Provide credentials
        UsernameAndPassword creds = new UsernameAndPassword("user", "pass");
        devTools.send(network.continueWithAuth(authReq, creds));
    } else {
        // Cancel authentication
        devTools.send(network.cancelAuth(authReq));
    }
});

// Set user agent
UserAgent customAgent = new UserAgent(
    "Mozilla/5.0 (Custom Browser)",
    Optional.of("en-US"),
    Optional.of("Linux")
);
devTools.send(network.setUserAgentOverride(customAgent));

Types

Network Event Types

// From v129.fetch.model package
import org.openqa.selenium.devtools.v129.fetch.model.AuthRequired;
import org.openqa.selenium.devtools.v129.fetch.model.RequestPaused;
import org.openqa.selenium.devtools.v129.fetch.model.AuthChallengeResponse;
import org.openqa.selenium.devtools.v129.fetch.model.RequestPattern;
import org.openqa.selenium.devtools.v129.fetch.model.RequestStage;

// Network request/response types
import org.openqa.selenium.devtools.v129.network.model.Request;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

Authentication Types

import org.openqa.selenium.UsernameAndPassword;

// Authentication challenge response
class AuthChallengeResponse {
    public enum Response {
        PROVIDECREDENTIALS,
        CANCELAUTH,
        DEFAULT
    }
    
    public AuthChallengeResponse(
        Response response,
        Optional<String> username,
        Optional<String> password
    );
}

User Agent Types

class UserAgent {
    public UserAgent(
        String userAgent,
        Optional<String> acceptLanguage,
        Optional<String> platform
    );
    
    public String userAgent();
    public Optional<String> acceptLanguage();
    public Optional<String> platform();
}

Install with Tessl CLI

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

docs

domains.md

events.md

index.md

javascript.md

logging.md

network.md

target.md

tile.json