mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Move path option into tracing.start (#192)
This consolidates all the tracing options in the tracing.start()
This commit is contained in:
parent
315c388f4d
commit
984e011cf0
14
docs/api.md
14
docs/api.md
@ -73,8 +73,8 @@
|
|||||||
+ [mouse.move(x, y)](#mousemovex-y)
|
+ [mouse.move(x, y)](#mousemovex-y)
|
||||||
+ [mouse.up([options])](#mouseupoptions)
|
+ [mouse.up([options])](#mouseupoptions)
|
||||||
* [class: Tracing](#class-tracing)
|
* [class: Tracing](#class-tracing)
|
||||||
+ [tracing.start([options])](#tracingstartoptions)
|
+ [tracing.start(options)](#tracingstartoptions)
|
||||||
+ [tracing.stop(path)](#tracingstoppath)
|
+ [tracing.stop()](#tracingstop)
|
||||||
* [class: Dialog](#class-dialog)
|
* [class: Dialog](#class-dialog)
|
||||||
+ [dialog.accept([promptText])](#dialogacceptprompttext)
|
+ [dialog.accept([promptText])](#dialogacceptprompttext)
|
||||||
+ [dialog.dismiss()](#dialogdismiss)
|
+ [dialog.dismiss()](#dialogdismiss)
|
||||||
@ -839,18 +839,18 @@ Dispatches a `mouseup` event.
|
|||||||
You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracingstoppath) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
|
You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracingstoppath) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
await page.tracing.start();
|
await page.tracing.start({path: 'trace.json'});
|
||||||
await page.navigate('https://www.google.com');
|
await page.navigate('https://www.google.com');
|
||||||
await page.tracing.stop('trace.json');
|
await page.tracing.stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### tracing.start([options])
|
#### tracing.start(options)
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
|
- `path` <[string]> A path to write the trace file to. **required**
|
||||||
- `screenshots` <[boolean]> captures screenshots in the trace.
|
- `screenshots` <[boolean]> captures screenshots in the trace.
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
#### tracing.stop(path)
|
#### tracing.stop()
|
||||||
- `path` <[string]> A path to write the trace file to.
|
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
### class: Dialog
|
### class: Dialog
|
||||||
|
@ -23,14 +23,16 @@ class Tracing {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
this._client = client;
|
this._client = client;
|
||||||
this._recording = false;
|
this._recording = false;
|
||||||
|
this._path = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object=} options
|
* @param {!Object} options
|
||||||
* @return {!Promise}
|
* @return {!Promise}
|
||||||
*/
|
*/
|
||||||
async start(options = {}) {
|
async start(options) {
|
||||||
console.assert(!this._recording, 'Cannot start recording trace while already recording trace.');
|
console.assert(!this._recording, 'Cannot start recording trace while already recording trace.');
|
||||||
|
console.assert(options.path, 'Must specify a path to write trace file to.');
|
||||||
|
|
||||||
const categoriesArray = [
|
const categoriesArray = [
|
||||||
'-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline',
|
'-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline',
|
||||||
@ -42,6 +44,7 @@ class Tracing {
|
|||||||
if (options.screenshots)
|
if (options.screenshots)
|
||||||
categoriesArray.push('disabled-by-default-devtools.screenshot');
|
categoriesArray.push('disabled-by-default-devtools.screenshot');
|
||||||
|
|
||||||
|
this._path = options.path;
|
||||||
this._recording = true;
|
this._recording = true;
|
||||||
await this._client.send('Tracing.start', {
|
await this._client.send('Tracing.start', {
|
||||||
transferMode: 'ReturnAsStream',
|
transferMode: 'ReturnAsStream',
|
||||||
@ -50,14 +53,13 @@ class Tracing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} path
|
|
||||||
* @return {!Promise}
|
* @return {!Promise}
|
||||||
*/
|
*/
|
||||||
async stop(path) {
|
async stop() {
|
||||||
let fulfill;
|
let fulfill;
|
||||||
let contentPromise = new Promise(x => fulfill = x);
|
let contentPromise = new Promise(x => fulfill = x);
|
||||||
this._client.once('Tracing.tracingComplete', event => {
|
this._client.once('Tracing.tracingComplete', event => {
|
||||||
this._readStream(event.stream, path).then(fulfill);
|
this._readStream(event.stream, this._path).then(fulfill);
|
||||||
});
|
});
|
||||||
await this._client.send('Tracing.end');
|
await this._client.send('Tracing.end');
|
||||||
this._recording = false;
|
this._recording = false;
|
||||||
|
10
test/test.js
10
test/test.js
@ -1503,23 +1503,23 @@ describe('Page', function() {
|
|||||||
fs.unlinkSync(outputFile);
|
fs.unlinkSync(outputFile);
|
||||||
});
|
});
|
||||||
it('should output a trace', SX(async function() {
|
it('should output a trace', SX(async function() {
|
||||||
await page.tracing.start({screenshots: true});
|
await page.tracing.start({screenshots: true, path: outputFile});
|
||||||
await page.navigate(PREFIX + '/grid.html');
|
await page.navigate(PREFIX + '/grid.html');
|
||||||
await page.tracing.stop(outputFile);
|
await page.tracing.stop();
|
||||||
expect(fs.existsSync(outputFile)).toBe(true);
|
expect(fs.existsSync(outputFile)).toBe(true);
|
||||||
}));
|
}));
|
||||||
it('should throw if tracing on two pages', SX(async function() {
|
it('should throw if tracing on two pages', SX(async function() {
|
||||||
await page.tracing.start();
|
await page.tracing.start({path: outputFile});
|
||||||
let newPage = await browser.newPage();
|
let newPage = await browser.newPage();
|
||||||
let error = null;
|
let error = null;
|
||||||
try {
|
try {
|
||||||
await newPage.tracing.start();
|
await newPage.tracing.start({path: outputFile});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
await newPage.close();
|
await newPage.close();
|
||||||
expect(error).toBeTruthy();
|
expect(error).toBeTruthy();
|
||||||
await page.tracing.stop(outputFile);
|
await page.tracing.stop();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user