Skip to content

Commit

Permalink
Report some Loaf data in upcoming Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Mar 6, 2024
1 parent 2274f48 commit 8aab6ad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions browserscripts/pageinfo/loaf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(function() {
// See https://developer.chrome.com/docs/web-platform/long-animation-frames
if (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {

const MAX_LOAFS_TO_CONSIDER = 10;
const relevantLoadEntries = [];
const observer = new PerformanceObserver(list => {
let longestBlockingLoAFs = [].concat(list.getEntries()).sort(
(a, b) => b.blockingDuration - a.blockingDuration
).slice(0, MAX_LOAFS_TO_CONSIDER);

// re-package
for (let entry of longestBlockingLoAFs) {
const info = {};
info.blockingDuration = entry.blockingDuration;
info.duration = entry.duration;
info.styleAndLayoutStart = entry.styleAndLayoutStart;
info.renderStart = entry.renderStart;
info.scripts = [];
for (let script of entry.scripts) {
const s = {};
s.forcedStyleAndLayoutDuration = script.forcedStyleAndLayoutDuration;
s.invoker = script.invoker;
s.invokerType = script.invokerType;
s.sourceFunctionName = script.sourceFunctionName;
s.sourceURL = script.sourceURL;
info.scripts.push(s);
}
relevantLoadEntries.push(info);
}
return relevantLoadEntries;
});
observer.observe({ type: 'long-animation-frame', buffered: true });
}
})();

0 comments on commit 8aab6ad

Please sign in to comment.