PerformanceObserver

PerformanceObserver interface is used to observe performance measurement events and be notified of new performance entries as they are recorded in the browser's performance timeline .

注意: 此特征可用于 Web 工作者 .

构造函数

PerformanceObserver()
Creates and returns a new PerformanceObserver 对象。

方法

PerformanceObserver.observe()
Specifies the set of entry types to observe. The performance observer's callback function will be invoked when a performance entry is recorded for one of the specified entryTypes
PerformanceObserver.disconnect()
Stops the performance observer callback from receiving performance entries .
PerformanceObserver.takeRecords()
Returns the current list of performance entries stored in the performance observer, emptying it out.

范例

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

规范

规范 状态 Comment
Performance Timeline Level 2
The definition of 'PerformanceObserver' in that specification.
候选推荐 Initial definition of PerformanceObserver 接口。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
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
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
disconnect 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
observe 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
supportedEntryTypes
Chrome 73 Edge ≤79 Firefox ? IE 不支持 No Opera Yes Safari 12.1 WebView Android 73 Chrome Android 73 Firefox Android ? Opera Android Yes Safari iOS 12.2 Samsung Internet Android 11.0
takeRecords
Chrome 65 Edge ≤79 Firefox 60 IE 不支持 No Opera Yes Safari 不支持 No WebView Android 65 Chrome Android 65 Firefox Android 60 Opera Android Yes Safari iOS 不支持 No Samsung Internet Android 9.0
Available in workers Chrome 62 Edge ≤79 Firefox ? IE 不支持 No Opera 49 Safari ? WebView Android 62 Chrome Android 62 Firefox Android ? Opera Android 46 Safari iOS ? Samsung Internet Android 8.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。

另请参阅