Chrome DevTools Protocol bindings for Selenium WebDriver version 111
—
Event domain implementation for console events, JavaScript exceptions, and runtime event management. Enables monitoring of browser console output, JavaScript execution errors, and runtime events for debugging and testing purposes.
Enable and disable the Chrome DevTools Runtime domain to receive events.
public Command<Void> enableRuntime();
public Command<Void> disableRuntime();Usage example:
v111Events events = domains.events();
// Enable runtime to receive events
devTools.send(events.enableRuntime());
// Later disable when done
devTools.send(events.disableRuntime());Monitor browser console API calls (console.log, console.error, etc.) and convert them to Selenium console events.
public Event<ConsoleAPICalled> consoleEvent();
public ConsoleEvent toConsoleEvent(ConsoleAPICalled event);Usage example:
// Listen for console API calls
devTools.addListener(events.consoleEvent(), consoleApiCall -> {
ConsoleEvent consoleEvent = events.toConsoleEvent(consoleApiCall);
System.out.println("Console " + consoleEvent.getType() + ": " +
consoleEvent.getArgs().stream()
.map(Object::toString)
.collect(Collectors.joining(" ")));
// Access timestamp
Instant timestamp = consoleEvent.getTimestamp();
System.out.println("At: " + timestamp);
});
// Page code that will trigger events:
// console.log("Hello from page");
// console.error("Error occurred");
// console.warn("Warning message");Monitor JavaScript exceptions thrown in the browser and convert them to Java exceptions.
public Event<ExceptionThrown> exceptionThrownEvent();
public JavascriptException toJsException(ExceptionThrown event);Usage example:
// Listen for JavaScript exceptions
devTools.addListener(events.exceptionThrownEvent(), exceptionThrown -> {
JavascriptException jsException = events.toJsException(exceptionThrown);
System.err.println("JavaScript Exception: " + jsException.getMessage());
// Print stack trace
for (StackTraceElement element : jsException.getStackTrace()) {
System.err.println(" at " + element.getMethodName() +
" (" + element.getFileName() + ":" + element.getLineNumber() + ")");
}
});
// Page code that will trigger exception:
// throw new Error("Something went wrong");
// undefinedFunction(); // ReferenceErrorclass ConsoleEvent {
public ConsoleEvent(String type, Instant timestamp, List<Object> args, List<RemoteObject> originalArgs);
public String getType(); // "log", "error", "warn", "info", etc.
public Instant getTimestamp(); // When the console call occurred
public List<Object> getArgs(); // Processed argument values
public List<RemoteObject> getOriginalArgs(); // Original CDP RemoteObject arguments
}
class RemoteObject {
public RemoteObject(String type, Object value);
public String getType(); // "string", "number", "boolean", "object", etc.
public Optional<Object> getValue(); // The actual value if primitive
}class JavascriptException extends RuntimeException {
public JavascriptException(String message);
// Inherits standard exception methods:
// public String getMessage();
// public StackTraceElement[] getStackTrace();
// public void setStackTrace(StackTraceElement[] stackTrace);
}class ConsoleAPICalled {
public ConsoleAPICalled.Type getType(); // Console API type
public List<org.openqa.selenium.devtools.v111.runtime.model.RemoteObject> getArgs(); // Arguments
public Timestamp getTimestamp(); // CDP timestamp
}
class ExceptionThrown {
public ExceptionDetails getExceptionDetails(); // Exception information
}
class ExceptionDetails {
public String getText(); // Exception message
public Optional<String> getUrl(); // Script URL where exception occurred
public int getLineNumber(); // Line number
public Optional<StackTrace> getStackTrace(); // Stack trace if available
public Optional<org.openqa.selenium.devtools.v111.runtime.model.RemoteObject> getException(); // Exception object
}
class StackTrace {
public List<CallFrame> getCallFrames(); // Stack frames
}
class CallFrame {
public String getFunctionName(); // Function name
public String getUrl(); // Script URL
public int getLineNumber(); // Line number
public int getColumnNumber(); // Column number
}The Events domain automatically handles conversion of CDP events to Java-friendly formats:
Instant objects for console eventsRemoteObject instances to simple Java objects where possibleExample handling missing information:
devTools.addListener(events.exceptionThrownEvent(), exceptionThrown -> {
JavascriptException jsException = events.toJsException(exceptionThrown);
// Stack trace will always be available, even if minimal
StackTraceElement[] stackTrace = jsException.getStackTrace();
if (stackTrace.length == 1 && "unknown".equals(stackTrace[0].getMethodName())) {
System.err.println("Exception with limited stack trace information");
}
});Install with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-devtools-v111