PressureRecord
注意:此功能在 Web Workers 中可用,但 Service Workers 除外。
PressureRecord 接口是 Compute Pressure API 的一部分,用于描述在特定过渡时刻的源的压力趋势。
实例属性
PressureRecord.source只读 实验性-
一个字符串,指示记录的来源。
PressureRecord.state只读 实验性-
一个字符串,指示记录的压力状态。
PressureRecord.time只读 实验性-
一个
DOMHighResTimeStamp,表示记录的时间戳。
实例方法
PressureRecord.toJSON()实验性-
返回
PressureRecord对象的 JSON 表示形式。
示例
使用 PressureRecord 对象
在下面的示例中,我们在压力观察者回调中记录 PressureRecord 对象的属性。
js
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
}
规范
| 规范 |
|---|
| 计算压力级别 1 # the-pressurerecord-interface |
浏览器兼容性
加载中…