PerformanceObserver()

PerformanceObserver() 构造函数使用给定的观察者 callback 生成一个新的 PerformanceObserver 对象.当通过 observe() 方法注册的 条目类型性能条目事件 被记录下来时,调用该观察者回调. 

语法

var observer = new PerformanceObserver(callback);

参数

callback
观察的性能事件被记录时将调用 PerformanceObserverCallback 回调. 调用回调时,其第一个参数是 性能观察条目列表,第二个参数是 观察者 对象。

返回值

一个在观察的性能事件发生时调用指定的 callback 的新 PerformanceObserver 对象.

例子

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

规范

Specification Status Comment
Performance Timeline Level 2
PerformanceObserver()
Candidate Recommendation PerformanceObserver() 构造函数的初始定义。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
PerformanceObserver() constructorChrome Full support 52Edge ? Firefox Full support 57IE No support NoOpera Full support 39Safari Full support 11WebView Android Full support 52Chrome Android Full support 52Firefox Android Full support 57Opera Android Full support 41Safari iOS Full support 11Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown