Puppeteer: How to get total bytes sent / received in a page

不羁岁月 提交于 2019-12-19 11:28:08

问题


Is there any puppeteer api/workaround to get total bytes sent / received in a page. For example below code gives me all timing stats.

await page.evaluate(() => JSON.stringify(window.performance.timing))

Similarly is there any way or work around I can get total bytes / sent received in a page. Byte counts should include HTTP, Websocket, XHR request / response headers, body all.


回答1:


By using

const perfEntries = JSON.parse(
  await page.evaluate(() => JSON.stringify(performance.getEntries()))
);

console.log(perfEntries);

You will get entries for all the requests.Add the size for all requests.

transferSize/encodedBodySize/decodedBodySize

{ name: 'https://www.google.com/',
    entryType: 'navigation',
    startTime: 0,
    duration: 7156.92000000854,
    initiatorType: 'navigation',
    nextHopProtocol: 'h2',
    workerStart: 0,
    redirectStart: 0,
    redirectEnd: 0,
    fetchStart: 1.7300000181421638,
    domainLookupStart: 1.7300000181421638,
    domainLookupEnd: 1.7300000181421638,
    connectStart: 1.7300000181421638,
    connectEnd: 1.7300000181421638,
    secureConnectionStart: 0,
    requestStart: 722.3000000230968,
    responseStart: 863.4900000179186,
    responseEnd: 948.6600000236649,
    transferSize: 64008,
    encodedBodySize: 63410,
    decodedBodySize: 216421,
    serverTiming: [],
    unloadEventStart: 0,
    unloadEventEnd: 0,
    domInteractive: 1416.8400000198744,
    domContentLoadedEventStart: 1416.880000004312,
    domContentLoadedEventEnd: 1424.5000000228174,
    domComplete: 7133.590000012191,
    loadEventStart: 7133.6149999988265,
    loadEventEnd: 7156.92000000854,
    type: 'navigate',
    redirectCount: 0 },...............................................]


来源:https://stackoverflow.com/questions/57601717/puppeteer-how-to-get-total-bytes-sent-received-in-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!