Package com.microsoft.playwright
Interface CDPSession
- All Known Implementing Classes:
CDPSessionImpl
public interface CDPSession
The
CDPSession instances are used to talk raw Chrome Devtools Protocol:
- protocol methods can be called with
session.sendmethod. - protocol events can be subscribed to with
session.onmethod.
Useful links:
- Documentation on DevTools Protocol can be found here: DevTools Protocol Viewer.
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
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);
-
Method Summary
Modifier and TypeMethodDescriptionvoiddetach()Detaches the CDPSession from the target.voidUnregister an event handler for events with the specified event name.voidRegister an event handler for events with the specified event name.default com.google.gson.JsonObjectcom.google.gson.JsonObject
-
Method Details
-
detach
void 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.- Since:
- v1.8
-
send
- Parameters:
method- Protocol method name.- Since:
- v1.8
-
send
- Parameters:
method- Protocol method name.args- Optional method parameters.- Since:
- v1.8
-
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.- Parameters:
eventName- CDP event name.handler- Event handler.- Since:
- v1.37
-
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.- Parameters:
eventName- CDP event name.handler- Event handler.- Since:
- v1.37
-