PressureRecord: state property

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Web Workers, except for Service Workers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The read-only state property is a string indicating the pressure state recorded.

Value

A string indicating the pressure state recorded. The Compute Pressure API uses human-readable pressure states with the following semantics (see also the specification):

Examples

undefined

Using the state property

In the following example we log the value of the state property in the pressure observer callback.

js
function callback(records) {
  const lastRecord = records[records.length - 1];
  console.log(`Current pressure is ${lastRecord.state}`);
}

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

Specifications