木偶:如何获取页面中发送/接收的总字节数 [英] Puppeteer: How to get total bytes sent / received in a page

查看:76
本文介绍了木偶:如何获取页面中发送/接收的总字节数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何伪造的api/解决方法来获取在页面中发送/接收的总字节数.例如下面的代码为我提供了所有计时统计信息.

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))

类似地,有什么办法或解决方法,我可以获取页面中收到的总字节数/已发送的总字节数.字节数应包括HTTP,Websocket,XHR请求/响应标头,正文.

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.

推荐答案

通过使用

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

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 },...............................................]

这篇关于木偶:如何获取页面中发送/接收的总字节数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆