feat(Tracing): allow custom tracing categories (#1439)

This patch adds `categories` option to the `page.tracing.start` method
that allows to override default tracing categories. 

References #1300, #854
This commit is contained in:
Slohmes 2017-12-03 18:36:34 -08:00 committed by Andrey Lushnikov
parent 42fd41c499
commit 5a6488883a
3 changed files with 10 additions and 1 deletions

View File

@ -1334,6 +1334,7 @@ await page.tracing.stop();
- `options` <[Object]>
- `path` <[string]> A path to write the trace file to. **required**
- `screenshots` <[boolean]> captures screenshots in the trace.
- `categories` <[Array]<[string]>> specify custom categories to use instead of default.
- returns: <[Promise]>
Only one trace can be active at a time per browser.

View File

@ -37,12 +37,13 @@ class Tracing {
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 defaultCategories = [
'-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline',
'disabled-by-default-devtools.timeline.frame', 'toplevel',
'blink.console', 'blink.user_timing', 'latencyInfo', 'disabled-by-default-devtools.timeline.stack',
'disabled-by-default-v8.cpu_profiler'
];
const categoriesArray = options.categories || defaultCategories;
if (options.screenshots)
categoriesArray.push('disabled-by-default-devtools.screenshot');

View File

@ -3005,6 +3005,13 @@ describe('Page', function() {
await page.tracing.stop();
expect(fs.existsSync(outputFile)).toBe(true);
}));
it('should run with custom categories if provided', SX(async function() {
await page.tracing.start({path: outputFile, categories: ['disabled-by-default-v8.cpu_profiler.hires']});
await page.tracing.stop();
const traceJson = JSON.parse(fs.readFileSync(outputFile));
expect(traceJson.metadata['trace-config']).toContain('disabled-by-default-v8.cpu_profiler.hires');
}));
it('should throw if tracing on two pages', SX(async function() {
await page.tracing.start({path: outputFile});
const newPage = await browser.newPage();