Skip to content

Commit 983a7b6

Browse files
authoredJun 22, 2020
docs(new): migrate CDPSession to TSDoc (#6064)
1 parent 1cf3f06 commit 983a7b6

11 files changed

+70
-121
lines changed
 

Diff for: ‎new-docs/puppeteer.cdpsession._callbacks.md

-11
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._connection.md

-11
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._constructor_.md

-22
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._onclosed.md

-15
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._onmessage.md

-22
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._sessionid.md

-11
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession._targettype.md

-11
This file was deleted.

Diff for: ‎new-docs/puppeteer.cdpsession.detach.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## CDPSession.detach() method
66

7+
Detaches the cdpSession from the target. Once detached, the cdpSession object won't emit any events and can't be used to send messages.
8+
79
<b>Signature:</b>
810

911
```typescript

Diff for: ‎new-docs/puppeteer.cdpsession.md

+22-14
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,42 @@
44

55
## CDPSession class
66

7+
The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
8+
79
<b>Signature:</b>
810

911
```typescript
1012
export declare class CDPSession extends EventEmitter
1113
```
1214
<b>Extends:</b> [EventEmitter](./puppeteer.eventemitter.md)
1315
14-
## Constructors
16+
## Remarks
1517
16-
| Constructor | Modifiers | Description |
17-
| --- | --- | --- |
18-
| [(constructor)(connection, targetType, sessionId)](./puppeteer.cdpsession._constructor_.md) | | Constructs a new instance of the <code>CDPSession</code> class |
18+
Protocol methods can be called with [CDPSession.send()](./puppeteer.cdpsession.send.md) method and protocol events can be subscribed to with `CDPSession.on` method.
19+
20+
Useful links: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/) and [Getting Started with DevTools Protocol](https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md)<!-- -->.
21+
22+
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CDPSession` class.
1923
20-
## Properties
24+
## Example
2125
22-
| Property | Modifiers | Type | Description |
23-
| --- | --- | --- | --- |
24-
| [\_callbacks](./puppeteer.cdpsession._callbacks.md) | | Map&lt;number, ConnectionCallback&gt; | |
25-
| [\_connection](./puppeteer.cdpsession._connection.md) | | [Connection](./puppeteer.connection.md) | |
26-
| [\_sessionId](./puppeteer.cdpsession._sessionid.md) | | string | |
27-
| [\_targetType](./puppeteer.cdpsession._targettype.md) | | string | |
26+
27+
```js
28+
const client = await page.target().createCDPSession();
29+
await client.send('Animation.enable');
30+
client.on('Animation.animationCreated', () => console.log('Animation created!'));
31+
const response = await client.send('Animation.getPlaybackRate');
32+
console.log('playback rate is ' + response.playbackRate);
33+
await client.send('Animation.setPlaybackRate', {
34+
playbackRate: response.playbackRate / 2
35+
});
36+
37+
```
2838
2939
## Methods
3040
3141
| Method | Modifiers | Description |
3242
| --- | --- | --- |
33-
| [\_onClosed()](./puppeteer.cdpsession._onclosed.md) | | |
34-
| [\_onMessage(object)](./puppeteer.cdpsession._onmessage.md) | | |
35-
| [detach()](./puppeteer.cdpsession.detach.md) | | |
43+
| [detach()](./puppeteer.cdpsession.detach.md) | | Detaches the cdpSession from the target. Once detached, the cdpSession object won't emit any events and can't be used to send messages. |
3644
| [send(method, params)](./puppeteer.cdpsession.send.md) | | |
3745

Diff for: ‎new-docs/puppeteer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| [Browser](./puppeteer.browser.md) | |
1313
| [BrowserContext](./puppeteer.browsercontext.md) | |
1414
| [BrowserFetcher](./puppeteer.browserfetcher.md) | |
15-
| [CDPSession](./puppeteer.cdpsession.md) | |
15+
| [CDPSession](./puppeteer.cdpsession.md) | The <code>CDPSession</code> instances are used to talk raw Chrome Devtools Protocol. |
1616
| [Connection](./puppeteer.connection.md) | |
1717
| [ConsoleMessage](./puppeteer.consolemessage.md) | |
1818
| [Coverage](./puppeteer.coverage.md) | |

Diff for: ‎src/common/Connection.ts

+45-3
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,44 @@ interface CDPSessionOnMessageObject {
167167
error: { message: string; data: any };
168168
result?: any;
169169
}
170+
171+
/**
172+
* The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
173+
*
174+
* @remarks
175+
*
176+
* Protocol methods can be called with {@link CDPSession.send} method and protocol
177+
* events can be subscribed to with `CDPSession.on` method.
178+
*
179+
* Useful links: {@link https://chromedevtools.github.io/devtools-protocol/ | DevTools Protocol Viewer}
180+
* and {@link https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md | Getting Started with DevTools Protocol}.
181+
*
182+
* @example
183+
* ```js
184+
* const client = await page.target().createCDPSession();
185+
* await client.send('Animation.enable');
186+
* client.on('Animation.animationCreated', () => console.log('Animation created!'));
187+
* const response = await client.send('Animation.getPlaybackRate');
188+
* console.log('playback rate is ' + response.playbackRate);
189+
* await client.send('Animation.setPlaybackRate', {
190+
* playbackRate: response.playbackRate / 2
191+
* });
192+
* ```
193+
*
194+
* @public
195+
*/
170196
export class CDPSession extends EventEmitter {
197+
/**
198+
* @internal
199+
*/
171200
_connection: Connection;
172-
_sessionId: string;
173-
_targetType: string;
174-
_callbacks: Map<number, ConnectionCallback> = new Map();
201+
private _sessionId: string;
202+
private _targetType: string;
203+
private _callbacks: Map<number, ConnectionCallback> = new Map();
175204

205+
/**
206+
* @internal
207+
*/
176208
constructor(connection: Connection, targetType: string, sessionId: string) {
177209
super();
178210
this._connection = connection;
@@ -206,6 +238,9 @@ export class CDPSession extends EventEmitter {
206238
});
207239
}
208240

241+
/**
242+
* @internal
243+
*/
209244
_onMessage(object: CDPSessionOnMessageObject): void {
210245
if (object.id && this._callbacks.has(object.id)) {
211246
const callback = this._callbacks.get(object.id);
@@ -221,6 +256,10 @@ export class CDPSession extends EventEmitter {
221256
}
222257
}
223258

259+
/**
260+
* Detaches the cdpSession from the target. Once detached, the cdpSession object
261+
* won't emit any events and can't be used to send messages.
262+
*/
224263
async detach(): Promise<void> {
225264
if (!this._connection)
226265
throw new Error(
@@ -231,6 +270,9 @@ export class CDPSession extends EventEmitter {
231270
});
232271
}
233272

273+
/**
274+
* @internal
275+
*/
234276
_onClosed(): void {
235277
for (const callback of this._callbacks.values())
236278
callback.reject(

0 commit comments

Comments
 (0)
Please sign in to comment.