-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpuppeteer-performance-metrics.js
30 lines (24 loc) · 1.19 KB
/
puppeteer-performance-metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const puppeteer = require('puppeteer');
const perfConfig = require('./config.performance.js');
const { gatherPerformanceTimingMetrics,
gatherLighthouseMetrics } = require('./helpers');
(async () => {
const browser = await puppeteer.launch({
headless: true
});
const page = await browser.newPage();
const urls = ['https://automationrhapsody.com/',
'https://automationrhapsody.com/examples/sample-login/'];
for (const url of urls) {
await page.goto(url);
const lighthouseMetrics = await gatherLighthouseMetrics(page, perfConfig);
const firstPaint = parseInt(lighthouseMetrics.audits['first-meaningful-paint']['rawValue'], 10);
const firstInteractive = parseInt(lighthouseMetrics.audits['first-interactive']['rawValue'], 10);
const navigationMetrics = await gatherPerformanceTimingMetrics(page);
const domInteractive = navigationMetrics.domInteractive - navigationMetrics.navigationStart;
const fullLoad = navigationMetrics.loadEventEnd - navigationMetrics.navigationStart;
console.log(`FirstPaint: ${firstPaint}, FirstInterractive: ${firstInteractive}, DOMInteractive: ${domInteractive}, FullLoad: ${fullLoad}`);
}
await browser.close();
})();