码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2018-02-20 17:02:52      阅读:493      评论:0      收藏:0      [点我收藏+]

标签:pos   new   rman   async   this   launch   span   art   rac   

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.

 

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

标签:pos   new   rman   async   this   launch   span   art   rac   

原文地址:https://www.cnblogs.com/Answer1215/p/8455377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!