PerformanceObserver: observe() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Note: This feature is available in Web Workers.

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.

Syntax

js
observe(options)

Parameters

options

An object with the following possible members:

buffered

A boolean flag to indicate whether buffered entries should be queued into the observer's buffer. Must be used only with the type option.

durationThreshold

A DOMHighResTimeStamp defining the threshold for PerformanceEventTiming entries. Defaults to 104ms and is rounded to the nearest of 8ms. Lowest possible threshold is 16ms. May not be used together with the entryTypes option.

entryTypes

An array of strings, each specifying one performance entry type to observe. May not be used together with the type, buffered, or durationThreshold options.

See PerformanceEntry.entryType for a list of valid performance entry type names. Unrecognized types are ignored, though the browser may output a warning message to the console to help developers debug their code. If no valid types are found, observe() has no effect.

type

A single string specifying exactly one performance entry type to observe. May not be used together with the entryTypes option.

Return value

None (undefined).

Examples

Watching multiple performance entry types

This example creates a PerformanceObserver and watches for "mark" and "measure" entry types as specified by the entryTypes option given in the observe() method.

js
const observer = new PerformanceObserver((list, obj) => {
  list.getEntries().forEach((entry) => {
    // Process "mark" and "measure" events
  });
});
observer.observe({ entryTypes: ["mark", "measure"] });

Watching a single performance entry type

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.

js
const observer = new PerformanceObserver((list, obj) => {
  list.getEntries().forEach((entry) => {
    // Process "resource" events
  });
});
observer.observe({ type: "resource", buffered: true });

Specifications

Specification
Performance Timeline
# dom-performanceobserver-observe

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
observe
Chrome – Full support
Chrome 52 (Release date: 2016-07-20)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote Full support
Opera – Full support
Opera 39 (Release date: 2016-08-02)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 52 (Release date: 2016-07-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 52 (Release date: 2016-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1.0.22 (Release date: 2024-01-10)
footnote Full support
Deno – Full support
Deno 2.7 (Release date: 2026-02-25)
footnote Full support
Node.js – Full support
Node.js 8.5 (Release date: 2017-09-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support