性能监测对象

Baseline Widely available *

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

* Some parts of this feature may have varying levels of support.

PerformanceObserver 用于监测性能度量事件,在浏览器的性能时间轴记录新的 performance entry 的时候将会被通知。

备注: 此特性在 Web Worker 中可用。

构造函数

PerformanceObserver()

创建并返回一个新的 PerformanceObserver 对象。

方法

PerformanceObserver.observe()

指定监测的 entry types 的集合。当 performance entry 被记录并且是指定的 entryTypes 之一的时候,性能观察者对象的回调函数会被调用。

PerformanceObserver.disconnect()

性能监测回调停止接收 性能条目

PerformanceObserver.takeRecords()

返回当前存储在性能观察器的 performance entry 列表,并将其清空。

示例

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

规范

Specification
Performance Timeline
# dom-performanceobserver

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
PerformanceObserver
PerformanceObserver() constructor
droppedEntriesCount() parameter
Experimental
disconnect
observe
supportedEntryTypes() static method
takeRecords
Available in workers

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Has more compatibility info.