blob: 09c83518ea97a150c396a2adf352e8ba8c1dcfd6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
---
title: PerformanceObserver.takeRecords()
slug: Web/API/PerformanceObserver/takeRecords
translation_of: Web/API/PerformanceObserver/takeRecords
---
<div>{{APIRef("Performance Timeline API")}}</div>
<div> </div>
<p>{{domxref('PerformanceObserver')}} 接口的 <strong><code>takeRecords()</code></strong> 方法返回当前存储在性能观察器中的 {{domxref("PerformanceEntry","性能条目")}} 列表,将其清空。</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">var PerformanceEntry[] = <em>performanceObserver</em>.takeRecords();
</pre>
<h3 id="参数">参数</h3>
<p>None.</p>
<h3 id="返回值">返回值</h3>
<p>{{domxref("PerformanceEntry")}} 对象列表.</p>
<h2 id="例子">例子</h2>
<pre class="brush: js">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"]});
var records = observer.takeRecords();
console.log(records[0].name);
console.log(records[0].startTime);
console.log(records[0].duration);
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-takerecords', 'takeRecords()')}}</td>
<td>{{Spec2('Performance Timeline Level 2')}}</td>
<td>Initial definition of <code>takeRecords()</code> method.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>
<p>{{Compat("api.PerformanceObserver.takeRecords")}}</p>
</div>
|