diff --git a/docs/api.md b/docs/api.md index f1f209d67bf..02a183280cc 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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. diff --git a/lib/Tracing.js b/lib/Tracing.js index 16f47331cec..bf421818dc8 100644 --- a/lib/Tracing.js +++ b/lib/Tracing.js @@ -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'); diff --git a/test/test.js b/test/test.js index c104e123ea2..6e68f684b94 100644 --- a/test/test.js +++ b/test/test.js @@ -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();