docs(new): migrate CDPSession to TSDoc (#6064)

This commit is contained in:
Alex Rudenko 2020-06-22 12:05:10 +02:00 committed by GitHub
parent 1cf3f06055
commit 983a7b67df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 72 additions and 123 deletions

View File

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_callbacks](./puppeteer.cdpsession._callbacks.md)
## CDPSession.\_callbacks property
<b>Signature:</b>
```typescript
_callbacks: Map<number, ConnectionCallback>;
```

View File

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_connection](./puppeteer.cdpsession._connection.md)
## CDPSession.\_connection property
<b>Signature:</b>
```typescript
_connection: Connection;
```

View File

@ -1,22 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [(constructor)](./puppeteer.cdpsession._constructor_.md)
## CDPSession.(constructor)
Constructs a new instance of the `CDPSession` class
<b>Signature:</b>
```typescript
constructor(connection: Connection, targetType: string, sessionId: string);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| connection | [Connection](./puppeteer.connection.md) | |
| targetType | string | |
| sessionId | string | |

View File

@ -1,15 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_onClosed](./puppeteer.cdpsession._onclosed.md)
## CDPSession.\_onClosed() method
<b>Signature:</b>
```typescript
_onClosed(): void;
```
<b>Returns:</b>
void

View File

@ -1,22 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_onMessage](./puppeteer.cdpsession._onmessage.md)
## CDPSession.\_onMessage() method
<b>Signature:</b>
```typescript
_onMessage(object: CDPSessionOnMessageObject): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| object | CDPSessionOnMessageObject | |
<b>Returns:</b>
void

View File

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_sessionId](./puppeteer.cdpsession._sessionid.md)
## CDPSession.\_sessionId property
<b>Signature:</b>
```typescript
_sessionId: string;
```

View File

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [CDPSession](./puppeteer.cdpsession.md) &gt; [\_targetType](./puppeteer.cdpsession._targettype.md)
## CDPSession.\_targetType property
<b>Signature:</b>
```typescript
_targetType: string;
```

View File

@ -4,6 +4,8 @@
## CDPSession.detach() method
Detaches the cdpSession from the target. Once detached, the cdpSession object won't emit any events and can't be used to send messages.
<b>Signature:</b>
```typescript

View File

@ -4,6 +4,8 @@
## CDPSession class
The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
<b>Signature:</b>
```typescript
@ -11,27 +13,33 @@ export declare class CDPSession extends EventEmitter
```
<b>Extends:</b> [EventEmitter](./puppeteer.eventemitter.md)
## Constructors
## Remarks
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(connection, targetType, sessionId)](./puppeteer.cdpsession._constructor_.md) | | Constructs a new instance of the <code>CDPSession</code> class |
Protocol methods can be called with [CDPSession.send()](./puppeteer.cdpsession.send.md) method and protocol events can be subscribed to with `CDPSession.on` method.
## Properties
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)<!-- -->.
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [\_callbacks](./puppeteer.cdpsession._callbacks.md) | | Map&lt;number, ConnectionCallback&gt; | |
| [\_connection](./puppeteer.cdpsession._connection.md) | | [Connection](./puppeteer.connection.md) | |
| [\_sessionId](./puppeteer.cdpsession._sessionid.md) | | string | |
| [\_targetType](./puppeteer.cdpsession._targettype.md) | | string | |
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.
## Example
```js
const client = await page.target().createCDPSession();
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
});
```
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [\_onClosed()](./puppeteer.cdpsession._onclosed.md) | | |
| [\_onMessage(object)](./puppeteer.cdpsession._onmessage.md) | | |
| [detach()](./puppeteer.cdpsession.detach.md) | | |
| [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. |
| [send(method, params)](./puppeteer.cdpsession.send.md) | | |

View File

@ -12,7 +12,7 @@
| [Browser](./puppeteer.browser.md) | |
| [BrowserContext](./puppeteer.browsercontext.md) | |
| [BrowserFetcher](./puppeteer.browserfetcher.md) | |
| [CDPSession](./puppeteer.cdpsession.md) | |
| [CDPSession](./puppeteer.cdpsession.md) | The <code>CDPSession</code> instances are used to talk raw Chrome Devtools Protocol. |
| [Connection](./puppeteer.connection.md) | |
| [ConsoleMessage](./puppeteer.consolemessage.md) | |
| [Coverage](./puppeteer.coverage.md) | |

View File

@ -167,12 +167,44 @@ interface CDPSessionOnMessageObject {
error: { message: string; data: any };
result?: any;
}
export class CDPSession extends EventEmitter {
_connection: Connection;
_sessionId: string;
_targetType: string;
_callbacks: Map<number, ConnectionCallback> = new Map();
/**
* The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
*
* @remarks
*
* Protocol methods can be called with {@link CDPSession.send} method and protocol
* events can be subscribed to with `CDPSession.on` method.
*
* Useful links: {@link https://chromedevtools.github.io/devtools-protocol/ | DevTools Protocol Viewer}
* and {@link https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md | Getting Started with DevTools Protocol}.
*
* @example
* ```js
* const client = await page.target().createCDPSession();
* 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
* });
* ```
*
* @public
*/
export class CDPSession extends EventEmitter {
/**
* @internal
*/
_connection: Connection;
private _sessionId: string;
private _targetType: string;
private _callbacks: Map<number, ConnectionCallback> = new Map();
/**
* @internal
*/
constructor(connection: Connection, targetType: string, sessionId: string) {
super();
this._connection = connection;
@ -206,6 +238,9 @@ export class CDPSession extends EventEmitter {
});
}
/**
* @internal
*/
_onMessage(object: CDPSessionOnMessageObject): void {
if (object.id && this._callbacks.has(object.id)) {
const callback = this._callbacks.get(object.id);
@ -221,6 +256,10 @@ export class CDPSession extends EventEmitter {
}
}
/**
* Detaches the cdpSession from the target. Once detached, the cdpSession object
* won't emit any events and can't be used to send messages.
*/
async detach(): Promise<void> {
if (!this._connection)
throw new Error(
@ -231,6 +270,9 @@ export class CDPSession extends EventEmitter {
});
}
/**
* @internal
*/
_onClosed(): void {
for (const callback of this._callbacks.values())
callback.reject(