Skip to main content

CDPSession

The CDPSession instances are used to talk raw Chrome Devtools Protocol:

  • protocol methods can be called with session.send method.
  • protocol events can be subscribed to with session.on method.

Useful links:

CDPSession client = page.context().newCDPSession(page);
client.send("Runtime.enable");

client.on("Animation.animationCreated", (event) -> System.out.println("Animation created!"));

JsonObject response = client.send("Animation.getPlaybackRate");
double playbackRate = response.get("playbackRate").getAsDouble();
System.out.println("playback rate is " + playbackRate);

JsonObject params = new JsonObject();
params.addProperty("playbackRate", playbackRate / 2);
client.send("Animation.setPlaybackRate", params);

方法 (Methods)

detach

Added before v1.9 cdpSession.detach

Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to send messages.

使用方式

CDPSession.detach();

傳回值


off

Added in: v1.37 cdpSession.off

Unregister an event handler for events with the specified event name. The given handler will not be called anymore for events with the given name.

使用方式

CDPSession.off(eventName, handler);

參數


on

Added in: v1.37 cdpSession.on

Register an event handler for events with the specified event name. The given handler will be called for every event with the given name.

使用方式

CDPSession.on(eventName, handler);

參數


send

Added before v1.9 cdpSession.send

使用方式

CDPSession.send(method);
CDPSession.send(method, args);

參數

  • method String#

    Protocol method name.

  • args JsonObject (optional) Added in: v1.37#

    Optional method parameters.

傳回值