Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium DevTools Event

From Leeroopedia
Knowledge Sources
Domains WebDriver, DevTools_Protocol
Last Updated 2026-02-12 00:00 GMT

Overview

The Event class is a generic container representing a Chrome DevTools Protocol event, encapsulating the event method name and a mapper function to deserialize event payloads.

Description

Event<X> models a CDP event that can be listened for through a DevTools session. Each event carries a method name (e.g., "Network.requestWillBeSent") and a Function<JsonInput, X> mapper that deserializes the incoming JSON event payload into the expected type X. The class provides a toString() override that returns the method name, making it convenient for logging and debugging purposes.

Usage

Use Event when subscribing to CDP events through a DevTools session. Like Command, events are typically instantiated by auto-generated CDP domain classes (e.g., Network.requestWillBeSent()), but can be constructed directly for custom or experimental CDP events.

Code Reference

Source Location

Signature

public class Event<X> {

  public Event(String method, Function<JsonInput, X> mapper)

  public String getMethod()
  public String toString()
}

Import

import org.openqa.selenium.devtools.Event;

I/O Contract

Constructor Parameters

Parameter Type Required Description
method String Yes The CDP event method name (e.g., "Network.requestWillBeSent")
mapper Function<JsonInput, X> Yes Function to deserialize the JSON event payload into type X

Return Values

Method Return Type Description
getMethod() String The CDP event method name
toString() String Returns the event method name (useful for logging)

Internal Access

Method Return Type Visibility Description
getMapper() Function<JsonInput, X> Package-private The mapper function used internally by the DevTools session to deserialize event data

Usage Examples

// Subscribing to a CDP event via the DevTools session
DevTools devTools = ((HasDevTools) driver).getDevTools();
devTools.createSession();

// Using auto-generated domain events (typical usage)
devTools.addListener(Network.requestWillBeSent(), requestWillBeSent -> {
    System.out.println("Request URL: " + requestWillBeSent.getRequest().getUrl());
});

// Creating a custom event manually
Event<Map<String, Object>> customEvent = new Event<>(
    "Runtime.consoleAPICalled",
    input -> input.read(new TypeToken<Map<String, Object>>(){}.getType())
);
devTools.addListener(customEvent, data -> {
    System.out.println("Console event: " + data);
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment