Compute Pressure APIwindow_and_worker_except_service
The PressureRecord interface is part of the Compute Pressure API and describes the pressure trend of a source at a specific moment of transition.
Instance properties
- PressureRecord.source
- : A string indicating the origin source from which the record is coming.
- PressureRecord.state
- : A string indicating the pressure state recorded.
- PressureRecord.time
- : A DOMHighResTimeStamp indicating the timestamp of the record.
Instance methods
- PressureRecord.toJSON()
- : Returns a JSON-serializable plain object representing the
PressureRecordobject. Automatically called by JSON.stringify().
- : Returns a JSON-serializable plain object representing the
Examples
Using the PressureRecord object
In the following example we log the properties of the PressureRecord object in the pressure observer callback.
function callback(records) {
const lastRecord = records[records.length - 1];
console.log(`Current pressure is ${lastRecord.state}`);
console.log(`Current pressure observed at ${lastRecord.time}`);
console.log(`Current pressure source: ${lastRecord.source}`);
}
try {
const observer = new PressureObserver(callback);
await observer.observe("cpu", {
sampleInterval: 1000, // 1000ms
});
} catch (error) {
// report error setting up the observer
}
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
