new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

cdpsession

10 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

CDPSession class purpose

CDPSession instances are used to talk raw Chrome DevTools Protocol. Protocol methods can be called with the session.send method. Protocol events can be subscribed to with the session.on method.

CDPSession created with newCDPSession

CDPSession is created by calling newCDPSession on a BrowserContext, passing a Page as an argument.

CDPSession.send method signature

CDPSession.send is an async method that takes a method name (string) and optional parameters. For JavaScript and Python, params is typed as Object. For C#, params is typed as Map<string, Object> with alias 'args'. For Java, params is typed as JsonObject with alias 'args'. The method returns Object for JavaScript, JsonElement? for C#, and JsonObject for Java. Since v1.8 (JS/Python), v1.30 (C#), and v1.37 (Java).

CDPSession.detach method

CDPSession.detach is an async method that detaches the CDPSession from the target. Once detached, the CDPSession object will not emit any events and cannot be used to send messages. Available since v1.8.

CDPSession.on method for event subscription

CDPSession.on is a method available in Java (since v1.37) that registers an event handler for events with a specified event name. It takes eventName (string) and handler (function taking JsonObject) as parameters. The handler will be called for every event with the given name.

CDPSession.off method for unregistering handlers

CDPSession.off is a method available in Java (since v1.37) that unregisters an event handler for events with a specified event name. It takes eventName (string) and handler (function taking JsonObject) as parameters. The handler will no longer be called for events with the given name.

CDPSession.event method for C#

CDPSession.event is a method available in C# (since v1.30) that returns an event emitter (CDPSessionEvent) for the given CDP event name. It takes eventName (string) as a parameter.

CDPSession close event

CDPSession emits a 'close' event when the session is closed, either because the target was closed or session.detach() was called. Available since v1.59.

CDPSession event property for JavaScript

CDPSession emits a generic 'event' event in JavaScript (since v1.59) for every CDP event received from the session. The event argument is an Object with properties method (string, the CDP event name) and params (optional Object, the CDP event parameters). This allows subscribing to all CDP events at once without knowing their names ahead of time.

CDPSession usage example with Animation protocol

Example showing how to create a CDPSession, enable the Animation protocol, subscribe to Animation.animationCreated events, get the playback rate, and set it to half: const client = await page.context().newCDPSession(page); await client.send('Animation.enable'); client.on('Animation.animationCreated', () => console.log('Animation created!')); const response = await client.send('Animation.getPlaybackRate'); console.log('playback rate is ' + response.playbackRate); await client.send('Animation.setPlaybackRate', { playbackRate: response.playbackRate / 2 });

Give your agent this brain