[Puppeteer] Get a Page's Load Time with Puppeteer (window.profermence.timing)
2021-02-13 21:19
阅读:435
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)
文章链接:http://soscw.com/index.php/essay/54982.html
文章标题:[Puppeteer] Get a Page's Load Time with Puppeteer (window.profermence.timing)
文章链接:http://soscw.com/index.php/essay/54982.html
评论
亲,登录后才可以留言!