puppeteer-har icon indicating copy to clipboard operation
puppeteer-har copied to clipboard

Created har file contents is empty.

Open yuji38kwmt opened this issue 5 years ago • 1 comments

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

  1. Why is sleep function needed?
  2. I do not want to specify milliseconds for sleep function. What function do I use ? For example, should I use await 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));
}

yuji38kwmt avatar Nov 28 '18 01:11 yuji38kwmt

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

bevrard avatar Sep 07 '23 13:09 bevrard