PerformanceObserver() 构造函数创建新 PerformanceObserver object with the given observer callback . The observer callback is invoked when performance entry events are recorded for the entry types that have been registered, via the observe() 方法。

句法

var observer = new PerformanceObserver(callback);
					

参数

callback
A PerformanceObserverCallback callback that will be invoked when observed performance events are recorded. When the callback is invoked, its first parameter is a list of performance observer entries and the second parameter is the observer 对象。

返回值

新的 PerformanceObserver object which will call the specified callback when observed performance events occur.

范例

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

规范

规范 状态 注释
Performance Timeline Level 2
The definition of 'PerformanceObserver()' in that specification.
候选推荐 Initial definition of PerformanceObserver() 构造函数。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
PerformanceObserver() 构造函数 Chrome 52 Edge ≤79 Firefox 57 IE 不支持 No Opera 39 Safari 11 WebView Android 52 Chrome Android 52 Firefox Android 57 Opera Android 41 Safari iOS 11 Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改: