Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
docs(new): Adds TSDoc to Tracing class (#6088)
* Adds tsdoc to Tracing class

* Updates tsdocs

Co-authored-by: martinsplitt <martin@geekonaut.de>
  • Loading branch information
2 people authored and mathiasbynens committed Jun 25, 2020
1 parent 60904da commit a46c78f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
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

0 comments on commit a46c78f

Please sign in to comment.