files/en-us/web/api/performanceobserver/index.md
{{APIRef("Performance API")}}{{AvailableInWorkers}}
The PerformanceObserver interface is used to observe performance measurement events and be notified of new {{domxref("PerformanceEntry","performance entries", '', 'true')}} as they are recorded in the browser's performance timeline.
PerformanceObserver object.entryTypes.The following example creates a PerformanceObserver watching for "mark" ({{domxref("PerformanceMark")}}) and "measure" ({{domxref("PerformanceMeasure")}}) events.
The perfObserver callback provides a list ({{domxref("PerformanceObserverEntryList")}}) which allows you to get observed performance entries.
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"] });
{{Specifications}}
{{Compat}}