-
Notifications
You must be signed in to change notification settings - Fork 14
/
pageLoadTime.js
31 lines (29 loc) · 1.23 KB
/
pageLoadTime.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
30
31
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
const tic = Date.now();
await page.goto('https://www.applaudsolutions.com/');
console.log('\n ////////////////////////////////////////////// ');
console.log(`page load took: ${Date.now() - tic}ms`);
const pref = await page.evaluate(() => {
const { loadEventEnd, navigationStart } = performance.timing;
const firstpaint =
chrome.loadTimes().firstPaintTime * 1000 - navigationStart;
return {
firstpaint,
loadTime: loadEventEnd - navigationStart,
loadTimes: JSON.stringify(chrome.loadTimes(), null, 4), // chrome specific
performance: JSON.stringify(performance.timing, null, 4),
};
});
console.log(`First paint: ${pref.firstpaint}ms`);
console.log(`page load took (performance): ${pref.loadTime}ms`);
console.log('\n ////////////////////////////////////////////// \n');
console.log('------------ chrome load times ------------');
console.log(pref.loadTimes);
console.log('------------ performance metrics ------------');
console.log(pref.performance);
await browser.close();
})();