This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
50 lines (44 loc) · 1.6 KB
/
script.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
import 'regenerator-runtime';
import { getLCP, getFID, getCLS } from 'web-vitals';
import TTI from 'tti-polyfill';
import { fps, all } from '../src/index.js';
window.addEventListener(
'load',
() => {
window.performance_information = {};
all().then((result) => {
console.log('all', performance.now());
Object.assign(window.performance_information, result);
print();
}).catch(console.error);
[
[getLCP, 'largest_contentful_paint'],
[getFID, 'first_input_delay'],
[getCLS, 'comulative_layout_shift']
].forEach(
([ fn, name ]) => fn(
({ value }) => {
console.log(name, performance.now());
window.performance_information[name] = value;
print();
}
)
);
fps().then((result) => {
console.log('fps', performance.now());
window.performance_information.frames_per_second = result;
print();
}).catch(console.error);
TTI.getFirstConsistentlyInteractive().then((result) => {
console.log('tti', performance.now());
window.performance_information.time_to_interactive = result || undefined;
print();
}).catch(console.error);
function print() {
document.querySelector('table').innerHTML = Object.entries(window.performance_information).map(
([key, value]) => `<tr><td>${key}</td><td>${value}</td></tr>`
).join('');
}
},
{ once: true }
);