-
Notifications
You must be signed in to change notification settings - Fork 90
/
nextjs-metrics.js
69 lines (57 loc) · 1.82 KB
/
nextjs-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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
let selector = '';
page.on('load', () => console.log('Loaded: ' + page.url()));
page.on('framenavigated', (frame) => {
console.log(`new url: ${frame.url()}`);
});
const navigationPromise = page.waitForNavigation({
waitUntil: 'networkidle2',
});
// Navigate to random Next.js page
await page.goto('https://new-app-3-op9eiblak.now.sh/');
console.log('\n==== localStorage hydration entry ====\n');
const hydrationData = await page.evaluate(() => {
const data = {
'before-hydrate-mark': localStorage.getItem('beforeRender'),
'after-hydrate-mark':
Number(localStorage.getItem('beforeRender')) +
Number(localStorage.getItem('Next.js-hydration')),
'hydration-duration': localStorage.getItem('Next.js-hydration'),
};
return data;
});
console.log(hydrationData);
await page.screenshot({
path: 'home-page.png',
fullPage: true,
});
await navigationPromise;
// Navigate to the Blog
selector = '#__next > div > nav > ul > li:nth-child(1) > a';
await Promise.all([
await page.waitForSelector(selector),
await page.click(selector, {
delay: 300,
}),
await page.waitFor(4000),
await navigationPromise,
]);
console.log('\n==== localStorage route change performance entries ====\n');
const routeChangeData = await page.evaluate(() => {
const data = {
'link-click-to-render-start-duration':
localStorage.getItem('Next.js-route-change-to-render'),
'render-duration': localStorage.getItem('Next.js-render'),
};
return data;
});
console.log(routeChangeData);
await page.screenshot({
path: 'blog-page.png',
fullPage: true,
});
await browser.close();
})();