MDN self-hosted library · e01.org

PressureRecord: toJSON() method

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

js
function callback(records) {
  const record = records[records.length - 1];

  const json = record.toJSON();
  console.log(json); // A plain object
  console.log(typeof json); // "object"
  console.log(json.state); // Same value as record.state
}

try {
  const observer = new PressureObserver(callback);
  await observer.observe("cpu", {
    sampleInterval: 1000, // 1000ms
  });
} catch (error) {
  // report error setting up the observer
}
js
console.log(JSON.stringify(record));