Documentation/PerformanceObserver
class

PerformanceObserver

js/performance.js:49
PerformanceObserver(callback)

Creates and returns a new PerformanceObserver object.

The observer callback is invoked when performance entry events are recorded by performance.mark() or performance.measure() calls for the entry types that have been registered, via the observe() method.

Parameters

NameTypeDescription
callbackfunction
propertyreadonly

supportedEntryTypes

js/performance.js:57
supportedEntryTypes: Array<string> = ["mark"

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

method

disconnect

js/performance.js:88
disconnect()

Stops the performance observer callback from receiving performance entries.

method

observe

js/performance.js:64
observe(options)

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.

Parameters

NameTypeDescription
optionsObject

An object with the following possible members:
entryTypes - An array of strings, each specifying one performance entry type to observe. May not be used together with the type
type - A single string specifying exactly one performance entry type to observe. May not be used together with the entryTypes option.

Example

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

takeRecords

js/performance.js:93
takeRecords()

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

Returns

Array<PerformanceEntry>