-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
content_script.js
64 lines (53 loc) · 1.51 KB
/
content_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
// communication type
const CONTENT = "content";
let paint = null;
let lcp = null;
/**
* Send performance data.
*
* @returns {void}
*/
function send() {
const response = {
type: CONTENT,
performance: {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1685688
navigation: JSON.parse(JSON.stringify(performance.getEntriesByType("navigation"))),
paint: JSON.parse(JSON.stringify(paint)),
lcp: JSON.parse(JSON.stringify(lcp))
}
};
// console.log(response);
browser.runtime.sendMessage(response);
}
new PerformanceObserver((list/* , observer */) => {
const entries = list.getEntries();
// console.log(entries);
// const entry = entries.find((x) => x.name === "first-contentful-paint");
// console.log(`First Contentful Paint: ${entry ? `${entry.startTime} ms` : "None"}`, entry);
paint = entries;
send();
}).observe({ type: "paint", buffered: true });
new PerformanceObserver((list/* , observer */) => {
const entries = list.getEntries();
// console.log(entries);
// const entry = entries.at(-1);
// console.log(`Largest Contentful Paint: ${entry.startTime} ms`, entry);
lcp = entries;
send();
}).observe({ type: "largest-contentful-paint", buffered: true });
if (document.readyState === "complete") {
send();
} else {
addEventListener("load", (/* event */) => {
send();
}, true);
}
browser.runtime.onMessage.addListener((message) => {
if (message.type === CONTENT) {
// console.log(message);
return Promise.resolve({ type: CONTENT });
}
});
console.log("Server Status loaded.");