[Puppeteer] Get a Page's Load Time with Puppeteer (window.profermence.timing)

In this lesson we are going to use Google's Puppeteer to gather metrics about a page's load time. We'll use a high level date subtraction method as well as gather data from the window performance timing. Then see how throttling the network to 3G affects the page's load time.

 

复制代码
const getPageMetrics = async ()  => {
    const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
 await page.waitFor(1000); //delay 1 s

  // 3G metwork
  await page._client.send('Network.emulateNetworkConditions', {
  offline: false,
  latency: 200,
  downloadThroughput: 780*1024 / 8,
  uploadThroughput: 300*1024/8
})
  await page.goto('https://developers.google.com/web/');

const pref = await page.evaluate( _ => {
  const {loadEventEnd, navigationStart} = window.performance.timing;
  return ({
    loadTime: loadEventEnd - navigationStart
  })
})

console.log(`It took: ${pref.loadTime}ms`)
}
复制代码

 

About 'winidow.profermence.timing', please check link.

About Chrom devtool protcol, please check link.

 

posted @   Zhentiw  阅读(451)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-02-20 [Angular] @ViewChild and template #refs to get Element Ref
2017-02-20 [Angular] @ViewChildren and QueryLists (ngAfterViewInit)
2017-02-20 [Angular] Difference between Providers and ViewProviders
2016-02-20 [Protractor] Use protractor to catch errors in the console
2016-02-20 [Cycle.js] Hyperscript as our alternative to template languages
点击右上角即可分享
微信分享提示