MDN self-hosted library · e01.org

LayoutShiftAttribution: toJSON() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
new PerformanceObserver((list) => {
  for (const { sources } of list.getEntries()) {
    if (sources) {
      const attribution = sources[0];

      const json = attribution.toJSON();
      console.log(json); // A plain object
      console.log(typeof json); // "object"
      console.log(json.previousRect.x); // Same value as attribution.previousRect.x
    }
  }
}).observe({ type: "layout-shift", buffered: true });
js
console.log(JSON.stringify(attribution));