The observe() method of the PerformanceObserver interface is used to specify the set of performance entry types to observe.
See PerformanceEntry.entryType for a list of entry types and PerformanceObserver.supportedEntryTypes for a list of entry types the user agent supports.
When a matching performance entry is recorded, the performance observer's callback function—set when creating the PerformanceObserver—is invoked.
This example creates a PerformanceObserver and watches for "mark" and "measure" entry types as specified by the entryTypes option given in the observe() method.
const observer = new PerformanceObserver((list, obj) => {
list.getEntries().forEach((entry) => {
});
});
observer.observe({ entryTypes: ["mark", "measure"] });
The following example retrieves buffered events and subscribes to newer events for resource timing events (PerformanceResourceTiming) using the buffered and type configuration options. Whenever you need to configure the observer to use the buffered or durationThreshold option, use type instead of entryType. Collecting multiple types of performance entry types will not work otherwise.
const observer = new PerformanceObserver((list, obj) => {
list.getEntries().forEach((entry) => {
});
});
observer.observe({ type: "resource", buffered: true });