puppeteer-har
puppeteer-har copied to clipboard
Created har file contents is empty.
I want to create har file of slow-loading website.
But created har file contents is empty.
I added sleep()
function after har.start()
, then har file contents is not empty.
Question
- Why is
sleep
function needed? - I do not want to specify milliseconds for
sleep
function. What function do I use ? For example, should I useawait page.waitForNavigation({ waitUntil: 'networkidle2' });
? https://github.com/GoogleChrome/puppeteer/issues/1916#issuecomment-368452496
{"log":{"version":"1.2","creator":{"name":"chrome-har","version":"0.4.1","comment":"https://github.com/sitespeedio/chrome-har"},"pages":[],"entries":[]}}
const puppeteer = require('puppeteer');
const PuppeteerHar = require('puppeteer-har');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const har = new PuppeteerHar(page);
await har.start({ path: 'results.har' });
// Added
await sleep(2000);
await page.goto('http://example.slowly.com');
await har.stop();
await browser.close();
})();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
await this.har.start({ path: `${flow.title}.har`, saveResponse: true, captureMimeTypes: ['application/font-sfnt','application/octet-stream', 'image/svg+xml', 'application/json','application/json; charset=UTF-8'] });
With this I get all answers