chore(docs): migrate Connection + CDP event defs (#6180)

This commit is contained in:
Jack Franklin 2020-07-08 11:11:01 +01:00 committed by GitHub
parent 74cb2ce7c2
commit 0e938803ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 29 additions and 336 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; [Connection](./puppeteer.connection.md) &gt; [\_callbacks](./puppeteer.connection._callbacks.md)
## Connection.\_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; [Connection](./puppeteer.connection.md) &gt; [\_closed](./puppeteer.connection._closed.md)
## Connection.\_closed property
<b>Signature:</b>
```typescript
_closed: boolean;
```

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; [Connection](./puppeteer.connection.md) &gt; [(constructor)](./puppeteer.connection._constructor_.md)
## Connection.(constructor)
Constructs a new instance of the `Connection` class
<b>Signature:</b>
```typescript
constructor(url: string, transport: ConnectionTransport, delay?: number);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| url | string | |
| transport | ConnectionTransport | |
| delay | number | |

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; [Connection](./puppeteer.connection.md) &gt; [\_delay](./puppeteer.connection._delay.md)
## Connection.\_delay property
<b>Signature:</b>
```typescript
_delay: number;
```

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; [Connection](./puppeteer.connection.md) &gt; [\_lastId](./puppeteer.connection._lastid.md)
## Connection.\_lastId property
<b>Signature:</b>
```typescript
_lastId: number;
```

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; [Connection](./puppeteer.connection.md) &gt; [\_onClose](./puppeteer.connection._onclose.md)
## Connection.\_onClose() method
<b>Signature:</b>
```typescript
_onClose(): 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; [Connection](./puppeteer.connection.md) &gt; [\_onMessage](./puppeteer.connection._onmessage.md)
## Connection.\_onMessage() method
<b>Signature:</b>
```typescript
_onMessage(message: string): Promise<void>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| message | string | |
<b>Returns:</b>
Promise&lt;void&gt;

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; [Connection](./puppeteer.connection.md) &gt; [\_rawSend](./puppeteer.connection._rawsend.md)
## Connection.\_rawSend() method
<b>Signature:</b>
```typescript
_rawSend(message: {}): number;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| message | {} | |
<b>Returns:</b>
number

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; [Connection](./puppeteer.connection.md) &gt; [\_sessions](./puppeteer.connection._sessions.md)
## Connection.\_sessions property
<b>Signature:</b>
```typescript
_sessions: Map<string, CDPSession>;
```

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; [Connection](./puppeteer.connection.md) &gt; [\_transport](./puppeteer.connection._transport.md)
## Connection.\_transport property
<b>Signature:</b>
```typescript
_transport: ConnectionTransport;
```

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; [Connection](./puppeteer.connection.md) &gt; [\_url](./puppeteer.connection._url.md)
## Connection.\_url property
<b>Signature:</b>
```typescript
_url: string;
```

View File

@ -1,24 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [Connection](./puppeteer.connection.md) &gt; [createSession](./puppeteer.connection.createsession.md)
## Connection.createSession() method
<b>Signature:</b>
```typescript
createSession(targetInfo: Protocol.Target.TargetInfo): Promise<CDPSession>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| targetInfo | Protocol.Target.TargetInfo | |
<b>Returns:</b>
Promise&lt;[CDPSession](./puppeteer.cdpsession.md)<!-- -->&gt;
{<!-- -->!Promise<!-- -->&lt;<!-- -->!CDPSession<!-- -->&gt;<!-- -->}

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; [Connection](./puppeteer.connection.md) &gt; [dispose](./puppeteer.connection.dispose.md)
## Connection.dispose() method
<b>Signature:</b>
```typescript
dispose(): 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; [Connection](./puppeteer.connection.md) &gt; [fromSession](./puppeteer.connection.fromsession.md)
## Connection.fromSession() method
<b>Signature:</b>
```typescript
static fromSession(session: CDPSession): Connection;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| session | [CDPSession](./puppeteer.cdpsession.md) | |
<b>Returns:</b>
[Connection](./puppeteer.connection.md)

View File

@ -1,45 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [Connection](./puppeteer.connection.md)
## Connection class
<b>Signature:</b>
```typescript
export declare class Connection extends EventEmitter
```
<b>Extends:</b> [EventEmitter](./puppeteer.eventemitter.md)
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(url, transport, delay)](./puppeteer.connection._constructor_.md) | | Constructs a new instance of the <code>Connection</code> class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [\_callbacks](./puppeteer.connection._callbacks.md) | | Map&lt;number, ConnectionCallback&gt; | |
| [\_closed](./puppeteer.connection._closed.md) | | boolean | |
| [\_delay](./puppeteer.connection._delay.md) | | number | |
| [\_lastId](./puppeteer.connection._lastid.md) | | number | |
| [\_sessions](./puppeteer.connection._sessions.md) | | Map&lt;string, [CDPSession](./puppeteer.cdpsession.md)<!-- -->&gt; | |
| [\_transport](./puppeteer.connection._transport.md) | | ConnectionTransport | |
| [\_url](./puppeteer.connection._url.md) | | string | |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [\_onClose()](./puppeteer.connection._onclose.md) | | |
| [\_onMessage(message)](./puppeteer.connection._onmessage.md) | | |
| [\_rawSend(message)](./puppeteer.connection._rawsend.md) | | |
| [createSession(targetInfo)](./puppeteer.connection.createsession.md) | | |
| [dispose()](./puppeteer.connection.dispose.md) | | |
| [fromSession(session)](./puppeteer.connection.fromsession.md) | <code>static</code> | |
| [send(method, params)](./puppeteer.connection.send.md) | | |
| [session(sessionId)](./puppeteer.connection.session.md) | | |
| [url()](./puppeteer.connection.url.md) | | |

View File

@ -1,23 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [Connection](./puppeteer.connection.md) &gt; [send](./puppeteer.connection.send.md)
## Connection.send() method
<b>Signature:</b>
```typescript
send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| method | T | |
| params | Protocol.CommandParameters\[T\] | |
<b>Returns:</b>
Promise&lt;Protocol.CommandReturnValues\[T\]&gt;

View File

@ -1,24 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [Connection](./puppeteer.connection.md) &gt; [session](./puppeteer.connection.session.md)
## Connection.session() method
<b>Signature:</b>
```typescript
session(sessionId: string): CDPSession | null;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| sessionId | string | |
<b>Returns:</b>
[CDPSession](./puppeteer.cdpsession.md) \| null
{<!-- -->?CDPSession<!-- -->}

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; [Connection](./puppeteer.connection.md) &gt; [url](./puppeteer.connection.url.md)
## Connection.url() method
<b>Signature:</b>
```typescript
url(): string;
```
<b>Returns:</b>
string

View File

@ -13,7 +13,6 @@
| [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. |
| [BrowserFetcher](./puppeteer.browserfetcher.md) | BrowserFetcher can download and manage different versions of Chromium and Firefox. |
| [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) | ConsoleMessage objects are dispatched by page via the 'console' event. |
| [Coverage](./puppeteer.coverage.md) | The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page. |
| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the <code>dialog</code> event. |

View File

@ -18,9 +18,8 @@ import { assert } from './assert';
import { helper } from './helper';
import { Target } from './Target';
import { EventEmitter } from './EventEmitter';
import { Events } from './Events';
import Protocol from '../protocol';
import { Connection } from './Connection';
import { Connection, ConnectionEmittedEvents } from './Connection';
import { Page } from './Page';
import { ChildProcess } from 'child_process';
import { Viewport } from './PuppeteerViewport';
@ -194,7 +193,7 @@ export class Browser extends EventEmitter {
);
this._targets = new Map();
this._connection.on(Events.Connection.Disconnected, () =>
this._connection.on(ConnectionEmittedEvents.Disconnected, () =>
this.emit(BrowserEmittedEvents.Disconnected)
);
this._connection.on('Target.targetCreated', this._targetCreated.bind(this));

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
import { assert } from './assert';
import { Events } from './Events';
import { debug } from './Debug';
const debugProtocolSend = debug('puppeteer:protocol:SEND ►');
const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀');
@ -30,6 +29,18 @@ interface ConnectionCallback {
method: string;
}
/**
* Internal events that the Connection class emits.
*
* @internal
*/
export const ConnectionEmittedEvents = {
Disconnected: Symbol('Connection.Disconnected'),
} as const;
/**
* @internal
*/
export class Connection extends EventEmitter {
_url: string;
_transport: ConnectionTransport;
@ -137,7 +148,7 @@ export class Connection extends EventEmitter {
this._callbacks.clear();
for (const session of this._sessions.values()) session._onClosed();
this._sessions.clear();
this.emit(Events.Connection.Disconnected);
this.emit(ConnectionEmittedEvents.Disconnected);
}
dispose(): void {
@ -168,6 +179,15 @@ interface CDPSessionOnMessageObject {
result?: any;
}
/**
* Internal events that the CDPSession class emits.
*
* @internal
*/
export const CDPSessionEmittedEvents = {
Disconnected: Symbol('CDPSession.Disconnected'),
} as const;
/**
* The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
*
@ -283,7 +303,7 @@ export class CDPSession extends EventEmitter {
);
this._callbacks.clear();
this._connection = null;
this.emit(Events.CDPSession.Disconnected);
this.emit(CDPSessionEmittedEvents.Disconnected);
}
}

View File

@ -22,6 +22,7 @@ import { FrameManager, Frame, FrameManagerEmittedEvents } from './FrameManager';
import { HTTPRequest } from './HTTPRequest';
import { HTTPResponse } from './HTTPResponse';
import { NetworkManagerEmittedEvents } from './NetworkManager';
import { CDPSessionEmittedEvents } from './Connection';
export type PuppeteerLifeCycleEvent =
| 'load'
@ -95,7 +96,7 @@ export class LifecycleWatcher {
this._eventListeners = [
helper.addEventListener(
frameManager._client,
Events.CDPSession.Disconnected,
CDPSessionEmittedEvents.Disconnected,
() =>
this._terminate(
new Error('Navigation failed because browser has disconnected!')

View File

@ -19,7 +19,7 @@ import { promisify } from 'util';
import { EventEmitter } from './EventEmitter';
import * as mime from 'mime';
import { Events } from './Events';
import { Connection, CDPSession } from './Connection';
import { Connection, CDPSession, CDPSessionEmittedEvents } from './Connection';
import { Dialog } from './Dialog';
import { EmulationManager } from './EmulationManager';
import { Frame, FrameManager, FrameManagerEmittedEvents } from './FrameManager';
@ -1325,7 +1325,7 @@ export class Page extends EventEmitter {
private _sessionClosePromise(): Promise<Error> {
if (!this._disconnectPromise)
this._disconnectPromise = new Promise((fulfill) =>
this._client.once(Events.CDPSession.Disconnected, () =>
this._client.once(CDPSessionEmittedEvents.Disconnected, () =>
fulfill(new Error('Target closed'))
)
);