I am trying to get a basic tracing example with screenshots option enabled work, however, it produces trace.json, but no screenshots.
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.tracing.start({screenshots: true, path: 'trace.json'});
await page.goto('https://www.google.com');
await page.tracing.stop();
await browser.close();
})();
What is the expected result?
What happens instead?
Using the following
@kesava Screenshots are embedded in the trace: try drag-and-dropping the trace.json
file into devtools performance panel.
If you do want to export the trace screenshots, this quick example based on @Everettss example in issue 1368 seem to work for me.
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.tracing.start({ screenshots: true, path: 'trace.json' });
await page.goto('https://www.google.com', { timeout: 60000 });
await page.tracing.stop();
// --- extracting data from trace.json ---
const tracing = JSON.parse(fs.readFileSync('./trace.json', 'utf8'));
const traceScreenshots = tracing.traceEvents.filter(x => (
x.cat === 'disabled-by-default-devtools.screenshot' &&
x.name === 'Screenshot' &&
typeof x.args !== 'undefined' &&
typeof x.args.snapshot !== 'undefined'
));
traceScreenshots.forEach(function(snap, index) {
fs.writeFile('trace-screenshot-'+index+'.png', snap.args.snapshot, 'base64', function(err) {
if (err) {
console.log('writeFile error', err);
}
});
});
// --- end extracting data from trace.json ---
await page.close();
})();
@QmarkC I think it fails when chrome crashes.
How can I implement this, so that I can know at which point chrome is crashed?
Most helpful comment
If you do want to export the trace screenshots, this quick example based on @Everettss example in issue 1368 seem to work for me.