W3cubDocs

/Web APIs

PerformanceObserver

Note: This feature is available in Web Workers

The PerformanceObserver interface is used to observe performance measurement events and be notified of new performance entries as they are recorded in the browser's performance timeline.

Constructor

PerformanceObserver()

Creates and returns a new PerformanceObserver object.

Static properties

PerformanceObserver.supportedEntryTypes Read only

Returns an array of the entryType values supported by the user agent.

Instance methods

PerformanceObserver.observe()

Specifies the set of entry types to observe. The performance observer's callback function will be invoked when performance entry is recorded for one of the specified entryTypes.

PerformanceObserver.disconnect()

Stops the performance observer callback from receiving performance entries.

PerformanceObserver.takeRecords()

Returns the current list of performance entries stored in the performance observer, emptying it out.

Examples

Creating a PerformanceObserver

The following example creates a PerformanceObserver watching for "mark" (PerformanceMark) and "measure" (PerformanceMeasure) events. The perfObserver callback provides a list (PerformanceObserverEntryList) which allows you to get observed performance entries.

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"] });

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
PerformanceObserver 52 79 57 No 39 11 52 52 57 41 11 6.0
PerformanceObserver 52 79 57 No 39 11 52 52 57 41 11 6.0
disconnect 52 79 57 No 39 11 52 52 57 41 11 6.0
observe 52 79 57 No 39 11 52 52 57 41 11 6.0
supportedEntryTypes_static 73 79 68 No 60 13 73 73 68 52 13 11.0
takeRecords 65 79 60 No 52 15 65 65 60 47 15 9.0
worker_support 62 79 57 No 49 11 62 62 57 46 11 8.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver