Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(new): Adds TSDoc to Tracing class #6088

Merged
merged 3 commits into from Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion new-docs/puppeteer.md
Expand Up @@ -34,7 +34,7 @@
| [Target](./puppeteer.target.md) | |
| [TimeoutError](./puppeteer.timeouterror.md) | TimeoutError is emitted whenever certain operations are terminated due to timeout. |
| [Touchscreen](./puppeteer.touchscreen.md) | The Touchscreen class exposes touchscreen events. |
| [Tracing](./puppeteer.tracing.md) | |
| [Tracing](./puppeteer.tracing.md) | The Tracing class exposes the tracing audit interface. |
| [WebWorker](./puppeteer.webworker.md) | The WebWorker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)<!-- -->. |

## Enumerations
Expand Down
20 changes: 0 additions & 20 deletions new-docs/puppeteer.tracing._constructor_.md

This file was deleted.

24 changes: 18 additions & 6 deletions new-docs/puppeteer.tracing.md
Expand Up @@ -4,17 +4,29 @@

## Tracing class

The Tracing class exposes the tracing audit interface.

<b>Signature:</b>

```typescript
export declare class Tracing
```

## Constructors
## Remarks

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(client)](./puppeteer.tracing._constructor_.md) | | Constructs a new instance of the <code>Tracing</code> class |
You can use `tracing.start` and `tracing.stop` to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/)<!-- -->.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Tracing` class.

## Example


```js
await page.tracing.start({path: 'trace.json'});
await page.goto('https://www.google.com');
await page.tracing.stop();

```

## Properties

Expand All @@ -28,6 +40,6 @@ export declare class Tracing

| Method | Modifiers | Description |
| --- | --- | --- |
| [start(options)](./puppeteer.tracing.start.md) | | |
| [stop()](./puppeteer.tracing.stop.md) | | |
| [start(options)](./puppeteer.tracing.start.md) | | Starts a trace for the current page. |
| [stop()](./puppeteer.tracing.stop.md) | | Stops a trace started with the <code>start</code> method. |

8 changes: 7 additions & 1 deletion new-docs/puppeteer.tracing.start.md
Expand Up @@ -4,6 +4,8 @@

## Tracing.start() method

Starts a trace for the current page.

<b>Signature:</b>

```typescript
Expand All @@ -14,9 +16,13 @@ start(options?: TracingOptions): Promise<void>;

| Parameter | Type | Description |
| --- | --- | --- |
| options | TracingOptions | |
| options | TracingOptions | Optional <code>TracingOptions</code>. |

<b>Returns:</b>

Promise&lt;void&gt;

## Remarks

Only one trace can be active at a time per browser.

4 changes: 4 additions & 0 deletions new-docs/puppeteer.tracing.stop.md
Expand Up @@ -4,6 +4,8 @@

## Tracing.stop() method

Stops a trace started with the `start` method.

<b>Signature:</b>

```typescript
Expand All @@ -13,3 +15,5 @@ stop(): Promise<Buffer>;

Promise&lt;Buffer&gt;

Promise which resolves to buffer with trace data.

26 changes: 26 additions & 0 deletions src/common/Tracing.ts
Expand Up @@ -23,15 +23,37 @@ interface TracingOptions {
categories?: string[];
}

/**
* The Tracing class exposes the tracing audit interface.
* @remarks
* You can use `tracing.start` and `tracing.stop` to create a trace file
* which can be opened in Chrome DevTools or {@link https://chromedevtools.github.io/timeline-viewer/ | timeline viewer}.
*
* @example
* ```js
* await page.tracing.start({path: 'trace.json'});
* await page.goto('https://www.google.com');
* await page.tracing.stop();
* ```
*/
export class Tracing {
_client: CDPSession;
_recording = false;
_path = '';

/**
* @internal
*/
constructor(client: CDPSession) {
this._client = client;
}

/**
* Starts a trace for the current page.
* @remarks
* Only one trace can be active at a time per browser.
* @param options - Optional `TracingOptions`.
*/
async start(options: TracingOptions = {}): Promise<void> {
assert(
!this._recording,
Expand Down Expand Up @@ -68,6 +90,10 @@ export class Tracing {
});
}

/**
* Stops a trace started with the `start` method.
* @returns Promise which resolves to buffer with trace data.
*/
async stop(): Promise<Buffer> {
let fulfill: (value: Buffer) => void;
const contentPromise = new Promise<Buffer>((x) => (fulfill = x));
Expand Down