blob: 3fe499226a405d170ab19db34d75056f53c42e10 (
plain)
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
|
function getResourceID(resourceName) {
return new Promise((resolve) => {
const observer = new PerformanceObserver((list) => {
const entries = list.getEntriesByType("resource");
for (const entry of entries) {
if (entry.name.endsWith(resourceName)) {
observer.disconnect();
resolve(`${entry.name}/${entry.startTime}`);
return;
}
}
});
observer.observe({ entryTypes: ["resource"] });
});
}
function getDocumentResourceID() {
return new Promise((resolve) => {
const observer = new PerformanceObserver((list) => {
const entries = list.getEntriesByType("navigation");
if (entries.length > 0) {
observer.disconnect();
const [entry] = entries;
const { name, startTime } = entry;
resolve(`${name}/${startTime}`);
}
});
observer.observe({ entryTypes: ["navigation"] });
});
}
|