跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

CDPSession ​

Added in: v1.8

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:

java
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 ​

cdpSession.detach() ​

Added in: v1.8

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.off() ​

Added in: v1.37

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.

Arguments

  • eventName string

    CDP event name.

  • handler function(JsonObject)

    Event handler.

cdpSession.on() ​

Added in: v1.37

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

Arguments

  • eventName string

    CDP event name.

  • handler function(JsonObject)

    Event handler.

cdpSession.send() ​

Added in: v1.8

Arguments

  • method string

    Protocol method name.

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

    Optional method parameters.

  • options Object (optional)

    • timeout float (optional) Added in: v1.65

      Maximum time in milliseconds to wait for the response. Defaults to 0 - no timeout.

Returns

  • JsonObject

Events ​

cdpSession.onClose() ​

Added in: v1.59

Emitted when the session is closed, either because the target was closed or session.detach() was called.

Event data

  • CDPSession

基于 Apache 2.0 许可证发布。