Skip to content

Instantly share code, notes, and snippets.

@victor-homyakov
Created February 4, 2026 18:25
Show Gist options
  • Select an option

  • Save victor-homyakov/b570f07d375dd73b95eb2bd17f26a825 to your computer and use it in GitHub Desktop.

Select an option

Save victor-homyakov/b570f07d375dd73b95eb2bd17f26a825 to your computer and use it in GitHub Desktop.
View CLS performance entries
(new PerformanceObserver((list) => {
const entries = list.getEntriesByType('layout-shift');
entries.forEach((/*LayoutShift*/entry) => {
console.log(entry);
const /*Array<LayoutShiftAttribution>*/sources = entry.sources || [];
const changes = [];
for (const source of sources) {
const { currentRect: cr, previousRect: pr, node } = source;
const dx = cr.x - pr.x;
const dy = cr.y - pr.y;
const ds = cr.width * cr.height - pr.width * pr.height;
changes.push({dx, dy, ds, node});
}
if (changes.length) {
console.table(changes);
}
});
})).observe({ type: 'layout-shift', buffered: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment