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 |
瀏覽器相容性
載入中…