From 8aab6adae2ef34812225dfb7bb7ef8741d70e043 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Wed, 6 Mar 2024 14:31:15 +0100 Subject: [PATCH] Report some Loaf data in upcoming Chrome --- browserscripts/pageinfo/loaf.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 browserscripts/pageinfo/loaf.js diff --git a/browserscripts/pageinfo/loaf.js b/browserscripts/pageinfo/loaf.js new file mode 100644 index 000000000..d1d085be5 --- /dev/null +++ b/browserscripts/pageinfo/loaf.js @@ -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 }); + } +})(); + \ No newline at end of file