sitespeedio / chrome-har

Create HAR files from Chrome Debugging Protocol data
MIT License
149 stars 50 forks source link

har.stop() - random error - "RangeError: Invalid time value" #61

Open amezioud opened 4 years ago

amezioud commented 4 years ago

My netsniffPrototype.js :

await this.page.goto(url, {timeout: 60000});
let cssSelectorconsent = '#consent-notice-agree-button';
let cookieAcceptBtn = await this.page.waitForSelector(cssSelectorconsent, { timeout: 60000, visible: true });
await cookieAcceptBtn.click();
await this.page.setCacheEnabled(false);
await this.harStart();
await this.page.reload({waituntil: networkidle2, timeout: 60000});
await this.harStop();

Add console.log in chrome-har/lib/entryFromResponse.js

  const entrySecs =
    page.__wallTime + (timing.requestTime - page.__timestamp);
  console.log('page.__wallTime  = ' + page.__wallTime + ' timing.requestTime =  ' + timing.requestTime + ' page.__timestamp  = ' + page.__timestamp)
  entry.startedDateTime = dayjs.unix(entrySecs).toISOString();
  console.log('dayjs.unix(entrySecs).toISOString() =  ' + dayjs.unix(entrySecs).toISOString())

Stdout results (Python call nodejs script using subprocess.run() ) :

2020-02-24:12:39:28,092 INFO [netsniffPrototype.js:296] <Thread(Thread-1, started daemon 140015018862336)> Stop Har events

page.wallTime = 1582544363.28644 timing.requestTime = 6971.141358 page.timestamp 6971.138063 dayjs.unix(entrySecs).toISOString() = 2020-02-24T11:39:23.289Z

page.wallTime = undefined timing.requestTime = 6971.149286 page.timestamp = undefined

2020-02-24:12:39:28,101 ERROR [netsniffPrototype.js:303] <Thread(Thread-1, started daemon 140015018862336)> Process exitHarNotStopped event Har not stopped properly ! e.stack => RangeError: Invalid time value at Date.toISOString () at h.d.toISOString (/home/pptruser/node_modules/dayjs/dayjs.min.js:1:6372) at module.exports (/home/pptruser/node_modules/chrome-har/lib/entryFromResponse.js:161:53) at harFromMessages (/home/pptruser/node_modules/chrome-har/index.js:310:15) at PuppeteerHar.stop (/home/pptruser/node_modules/puppeteer-har/lib/PuppeteerHar.js:109:21) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:97:5)

soulgalore commented 4 years ago

It looks like something is broken upstream or can you show me what's not working in Chrome-har? I don't follow.

amezioud commented 4 years ago

what could have happened upstream?

amezioud commented 4 years ago

If I start the har capture without reloading, it works everytime without issue.