PerformanceObserverEntryList

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

注意:此功能在 Web Workers 中可用。

PerformanceObserverEntryList 介面是可透過 observe() 方法顯式觀察到的 效能事件 列表。

例項方法

PerformanceObserverEntryList.getEntries()

返回所有顯式觀察到的 PerformanceEntry 物件列表。

PerformanceObserverEntryList.getEntriesByType()

返回給定條目型別的所有顯式觀察到的 PerformanceEntry 物件列表。

PerformanceObserverEntryList.getEntriesByName()

根據給定的名稱和條目型別,返回所有顯式觀察到的 PerformanceEntry 物件列表。

示例

使用 PerformanceObserverEntryList

在以下示例中,listPerformanceObserverEntryList 物件。呼叫 getEntries() 方法來獲取所有顯式觀察到的 PerformanceEntry 物件,在本例中是“measure”和“mark”。

js
function perfObserver(list, observer) {
  list.getEntries().forEach((entry) => {
    if (entry.entryType === "mark") {
      console.log(`${entry.name}'s startTime: ${entry.startTime}`);
    }
    if (entry.entryType === "measure") {
      console.log(`${entry.name}'s duration: ${entry.duration}`);
    }
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark"] });

規範

規範
效能時間線
# performanceobserverentrylist-interface

瀏覽器相容性