Chrome DevTools Protocol version 129 bindings for Selenium WebDriver.
—
The v129Events class provides comprehensive console and exception event handling from the Chrome DevTools Protocol. It captures console messages, JavaScript exceptions, and converts them to Selenium-compatible event objects.
Core events domain for console and exception handling.
/**
* Events domain for console and exception handling
* @param devtools - DevTools instance for protocol communication
*/
public class v129Events extends Events<ConsoleAPICalled, ExceptionThrown> {
public v129Events(DevTools devtools);
}Enable and disable the Runtime domain for event capture.
/**
* Enables the Runtime domain to start receiving events
* @return Command to enable Runtime domain
*/
protected Command<Void> enableRuntime();
/**
* Disables the Runtime domain to stop receiving events
* @return Command to disable Runtime domain
*/
protected Command<Void> disableRuntime();Capture and process console API calls from the browser.
/**
* Event fired when console API is called (console.log, console.error, etc.)
* @return Event for console API calls
*/
protected Event<ConsoleAPICalled> consoleEvent();
/**
* Converts CDP console event to Selenium ConsoleEvent
* @param event - ConsoleAPICalled event from CDP
* @return ConsoleEvent with processed timestamp and arguments
*/
protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event);Capture and process JavaScript exceptions from the browser.
/**
* Event fired when a JavaScript exception is thrown
* @return Event for JavaScript exceptions
*/
protected Event<ExceptionThrown> exceptionThrownEvent();
/**
* Converts CDP exception event to JavascriptException
* @param event - ExceptionThrown event from CDP
* @return JavascriptException with stack trace and error details
*/
protected JavascriptException toJsException(ExceptionThrown event);Usage Examples:
import org.openqa.selenium.devtools.v129.v129Events;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.events.ConsoleEvent;
import org.openqa.selenium.JavascriptException;
// Create events domain
DevTools devTools = driver.getDevTools();
v129Events events = new v129Events(devTools);
// Enable runtime for event capture
devTools.send(events.enableRuntime());
// Listen for console events
devTools.addListener(events.consoleEvent(), consoleEvent -> {
ConsoleEvent seleniumEvent = events.toConsoleEvent(consoleEvent);
System.out.println("Console " + seleniumEvent.getType() + ": " +
seleniumEvent.getMessages());
});
// Listen for JavaScript exceptions
devTools.addListener(events.exceptionThrownEvent(), exceptionEvent -> {
JavascriptException jsException = events.toJsException(exceptionEvent);
System.err.println("JavaScript Error: " + jsException.getMessage());
jsException.printStackTrace();
});
// Navigate to trigger events
driver.get("https://example.com");
// Execute JavaScript that generates console output
driver.executeScript("console.log('Hello from JavaScript');");
driver.executeScript("console.error('This is an error message');");
// Execute JavaScript that throws an exception
try {
driver.executeScript("throw new Error('Test exception');");
} catch (Exception e) {
// Exception will also be captured by DevTools listener
}
// Cleanup
devTools.send(events.disableRuntime());// Filter console events by type
devTools.addListener(events.consoleEvent(), consoleEvent -> {
ConsoleEvent event = events.toConsoleEvent(consoleEvent);
switch (event.getType()) {
case "log":
// Handle regular log messages
break;
case "error":
// Handle error messages
break;
case "warn":
// Handle warning messages
break;
case "debug":
// Handle debug messages
break;
}
});
// Extract stack trace from exceptions
devTools.addListener(events.exceptionThrownEvent(), exceptionEvent -> {
JavascriptException jsException = events.toJsException(exceptionEvent);
// Get stack trace elements
StackTraceElement[] stackTrace = jsException.getStackTrace();
for (StackTraceElement element : stackTrace) {
System.out.println(" at " + element.getMethodName() +
" (" + element.getFileName() + ":" + element.getLineNumber() + ")");
}
});// From v129.runtime.model package
import org.openqa.selenium.devtools.v129.runtime.model.ConsoleAPICalled;
import org.openqa.selenium.devtools.v129.runtime.model.ExceptionThrown;
import org.openqa.selenium.devtools.v129.runtime.model.ExceptionDetails;
import org.openqa.selenium.devtools.v129.runtime.model.StackTrace;
// Selenium event types
import org.openqa.selenium.devtools.events.ConsoleEvent;
import org.openqa.selenium.JavascriptException;// ConsoleEvent from Selenium
class ConsoleEvent {
public ConsoleEvent(
String type,
Instant timestamp,
List<Object> messages,
List<RemoteObject> args
);
public String getType();
public Instant getTimestamp();
public List<Object> getMessages();
public List<RemoteObject> getArgs();
}// ExceptionDetails from CDP
class ExceptionDetails {
public String getText();
public Optional<String> getUrl();
public int getLineNumber();
public Optional<StackTrace> getStackTrace();
public Optional<RemoteObject> getException();
}
// StackTrace from CDP
class StackTrace {
public List<CallFrame> getCallFrames();
}
// CallFrame from CDP
class CallFrame {
public String getFunctionName();
public String getUrl();
public int getLineNumber();
public int getColumnNumber();
}// RemoteObject for console arguments
import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;
class RemoteObject {
public RemoteObject(String type, Object value);
public String getType();
public Optional<Object> getValue();
public Optional<String> getDescription();
}Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-devtools-v129