const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (!entry.sources || entry.sources.length === 0) continue;
const mostImpactfulSource = entry.sources[0];
console.log("Layout shift score:", entry.value);
console.log("Most impactful element:", mostImpactfulSource.node);
console.log("Previous position:", mostImpactfulSource.previousRect);
console.log("Current position:", mostImpactfulSource.currentRect);
}
});
observer.observe({ type: "layout-shift", buffered: true });LayoutShiftAttribution / notebook
LayoutShiftAttribution
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.