PerformanceObserver.observe()

This article needs a technical review. How you can help.

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The observe() method is used to specify the set of performance interface types to observe. The performance observer's callback function will be invoked when a performance entry is recorded for one of the specified types.

The types are specified in an array of strings and the valid values are defined in PerformanceEntry.entryType.

SyntaxEdit

observer.observe(options);

Arguments

options
A PerformanceObserverInit dictionary with one member:
  • "entryTypes", an array of strings and the valid values for the strings are defined in PerformanceEntry.entryType. If a value is not valid, the browser will ignore it. If the options argument is not given or the array is empty, TypeError is thrown.

Return value

void

ExampleEdit

var observer = new PerformanceObserver(function(list, obj) {
  var entries = list.getEntries();
  for (var i=0; i < entries.length; i++) {
    // Process "mark" and "frame" events
  }
});
observer.observe({entryTypes: ["mark", "frame"]});

function perf_observer(list, observer) {
  // Process the "measure" event 
}
var observer2 = new PerformanceObserver(perf_observer);
observer2.observe({entryTypes: ["measure"]});

SpecificationsEdit

Specification Status Comment
Performance Timeline Time Level 2
The definition of 'observe()' in that specification.
Editor's Draft Initial definition of observe() method.

Browser compatibilityEdit

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
observe() method No support No support No support No support No support

Document Tags and Contributors

 Contributors to this page: rolfedh, AFBarstow
 Last updated by: rolfedh,