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

logging.mddocs/

Logging System

Access to browser logs including console logs, network logs, and other browser-generated log messages. Provides structured access to Chrome's logging system with proper log level conversion.

Capabilities

Log Domain Control

Enable and manage the Chrome DevTools logging domain for comprehensive log access.

/**
 * Initialize logging handler 
 */
public V105Log();

/**
 * Enable logging domain to start receiving log events
 * @return Command to enable logging domain
 */
public Command<Void> enable();

/**
 * Clear all browser logs
 * @return Command to clear browser log entries
 */
public Command<Void> clear();

Usage Examples:

import org.openqa.selenium.devtools.v105.V105Log;

// Initialize logging
V105Log log = new V105Log();

// Enable logging domain
devTools.send(log.enable());

// Clear existing logs
devTools.send(log.clear());

// Navigate and generate some logs
driver.get("https://example.com");

// Disable logging when done
// (Note: V105Log doesn't expose disable, logs remain active until session ends)

Log Entry Monitoring

Monitor and capture log entries as they are generated by the browser.

/**
 * Get log entry added event stream
 * @return Event stream for new log entries
 */
public Event<org.openqa.selenium.devtools.idealized.log.model.LogEntry> entryAdded();

Usage Examples:

import org.openqa.selenium.devtools.idealized.log.model.LogEntry;
import java.util.logging.Level;

// Set up log monitoring
log.entryAdded().addListener(logEntry -> {
    System.out.println("Log Source: " + logEntry.getSource());
    System.out.println("Level: " + logEntry.getLogEntry().getLevel());
    System.out.println("Message: " + logEntry.getLogEntry().getMessage());
    System.out.println("Timestamp: " + logEntry.getLogEntry().getMillis());
    System.out.println("---");
});

// Generate different types of logs
devTools.send(Runtime.evaluate("console.log('Info message')"));
devTools.send(Runtime.evaluate("console.warn('Warning message')"));
devTools.send(Runtime.evaluate("console.error('Error message')"));

// Navigate to trigger network logs
driver.get("https://httpbin.org/status/404"); // Will generate network error logs

Log Level Conversion

Automatic conversion between Chrome DevTools Protocol log levels and Java logging levels.

/**
 * Convert CDP log level to Java logging level
 * @param level CDP log level
 * @return Java logging Level
 */
private Level fromCdpLevel(LogEntry.Level level);

/**
 * Convert CDP timestamp to epoch milliseconds
 * @param timestamp CDP timestamp
 * @return Epoch milliseconds as long
 */
private long fromCdpTimestamp(Timestamp timestamp);

Usage Examples:

// The conversion happens automatically in entryAdded() events
log.entryAdded().addListener(logEntry -> {
    Level javaLevel = logEntry.getLogEntry().getLevel();
    
    // Handle different log levels
    if (javaLevel.equals(Level.SEVERE)) {
        handleError(logEntry);
    } else if (javaLevel.equals(Level.WARNING)) {
        handleWarning(logEntry);
    } else if (javaLevel.equals(Level.INFO)) {
        handleInfo(logEntry);
    } else if (javaLevel.equals(Level.FINEST)) {
        handleVerbose(logEntry);
    }
});

private void handleError(LogEntry logEntry) {
    System.err.println("ERROR: " + logEntry.getLogEntry().getMessage());
    // Log to file, send alert, etc.
}

private void handleWarning(LogEntry logEntry) {
    System.out.println("WARNING: " + logEntry.getLogEntry().getMessage());
    // Track warnings for analysis
}

Advanced Log Filtering

Filter and process logs based on source and content.

Usage Examples:

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class LogAnalyzer {
    private final Map<String, AtomicInteger> logCounts = new ConcurrentHashMap<>();
    private final List<LogEntry> errorLogs = new ArrayList<>();
    
    public void startLogAnalysis(V105Log log) {
        log.entryAdded().addListener(this::analyzeLogEntry);
    }
    
    private void analyzeLogEntry(LogEntry logEntry) {
        String source = logEntry.getSource();
        Level level = logEntry.getLogEntry().getLevel();
        String message = logEntry.getLogEntry().getMessage();
        
        // Count logs by source
        logCounts.computeIfAbsent(source, k -> new AtomicInteger(0)).incrementAndGet();
        
        // Collect error logs for analysis
        if (level.equals(Level.SEVERE)) {
            errorLogs.add(logEntry);
        }
        
        // Filter specific patterns
        if (message.contains("Failed to load resource")) {
            handleResourceLoadError(logEntry);
        } else if (message.contains("CSP")) {
            handleSecurityPolicyViolation(logEntry);
        } else if (source.equals("network") && level.equals(Level.WARNING)) {
            handleNetworkWarning(logEntry);
        }
    }
    
    public void printLogSummary() {
        System.out.println("Log Summary:");
        logCounts.forEach((source, count) -> 
            System.out.println(source + ": " + count.get() + " entries"));
            
        System.out.println("Total errors: " + errorLogs.size());
    }
}

// Usage
LogAnalyzer analyzer = new LogAnalyzer();
analyzer.startLogAnalysis(log);

// Run tests or navigate pages
driver.get("https://example.com");

// Get summary
analyzer.printLogSummary();

Types

Core Logging Types

// Logging implementation
public class V105Log implements org.openqa.selenium.devtools.idealized.log.Log {
    public V105Log();
    
    Command<Void> enable();
    Command<Void> clear();
    Event<org.openqa.selenium.devtools.idealized.log.model.LogEntry> entryAdded();
}

// Idealized log entry for Selenium
public class org.openqa.selenium.devtools.idealized.log.model.LogEntry {
    LogEntry(String source, org.openqa.selenium.logging.LogEntry logEntry);
    
    String getSource();
    org.openqa.selenium.logging.LogEntry getLogEntry();
}

// Selenium log entry
public class org.openqa.selenium.logging.LogEntry {
    LogEntry(Level level, long timestamp, String message);
    
    Level getLevel();
    long getMillis();
    String getMessage();
}

CDP Log Types

// CDP log entry
public class org.openqa.selenium.devtools.v105.log.model.LogEntry {
    LogEntry.Level getLevel();
    String getText();
    String getSource();
    Timestamp getTimestamp();
    Optional<String> getUrl();
    Optional<Integer> getLineNumber();
    Optional<StackTrace> getStackTrace();
}

// CDP log levels
public enum LogEntry.Level {
    VERBOSE("verbose"),
    INFO("info"), 
    WARNING("warning"),
    ERROR("error");
    
    String toString();
}

// CDP timestamp
public class Timestamp {
    Timestamp(Number timestamp);
    
    Number toJson();
    String toString();
}

Java Logging Integration

// Java logging levels used in conversion
public class Level {
    public static final Level FINEST;   // Maps from CDP "verbose"
    public static final Level INFO;     // Maps from CDP "info"
    public static final Level WARNING;  // Maps from CDP "warning"
    public static final Level SEVERE;   // Maps from CDP "error"
}

Log Sources

Common log sources you may encounter:

  • "console" - Console API messages (console.log, console.error, etc.)
  • "network" - Network-related messages and errors
  • "security" - Security policy violations and warnings
  • "deprecation" - Deprecated API usage warnings
  • "worker" - Web Worker and Service Worker messages
  • "storage" - Storage-related messages (localStorage, sessionStorage, etc.)
  • "appcache" - Application Cache messages (deprecated)
  • "rendering" - Rendering engine messages
  • "javascript" - JavaScript engine messages
  • "xml" - XML parsing messages

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