PerformanceObserverEntryList.getEntries() - Web APIs 编辑
The getEntries()
method of the PerformanceObserverEntryList
interface returns a list of explicitly observed performance entry objects for a given filter. The list's members are determined by the set of entry types specified in the call to the observe()
method. The list is available in the observer's callback function (as the first parameter in the callback).
This method is exposed to Window
and Worker
interfaces.
Syntax
General syntax:
entries = list.getEntries(); entries = list.getEntries(PerformanceEntryFilterOptions);
Specific usage:
entries = list.getEntries({name: "entry_name", entryType: "mark"});
Parameters
PerformanceEntryFilterOptions
Optional
- Is a
PerformanceEntryFilterOptions
dictionary, having the following fields:"name"
, the name of a performance entry."entryType"
, the entry type. The valid entry types are listed in thePerformanceEntry.entryType
method."initiatorType"
, the type of the initiating resource (for example an HTML element). The values are defined by thePerformanceResourceTiming.initiatorType
interface.
Return value
A list of explicitly observed PerformanceEntry
objects that meets the criteria of the filter. The items will be in chronological order based on the entries' startTime
. If no objects that meet the filter are found, an empty list is returned. If no argument is given, all entries are returned.
Example
function print_perf_entry(pe) {
console.log("name: " + pe.name +
"; entryType: " + pe.entryType +
"; startTime: " + pe.startTime +
"; duration: " + pe.duration);
}
// Create observer for all performance event types
var observe_all = new PerformanceObserver(function(list, obs) {
var perfEntries;
// Print all entries
perfEntries = list.getEntries();
for (var i=0; i < perfEntries.length; i++) {
print_perf_entry(perfEntries[i]);
}
// Print entries named "Begin" with type "mark"
perfEntries = list.getEntriesByName("Begin", "mark");
for (var i=0; i < perfEntries.length; i++) {
print_perf_entry(perfEntries[i]);
}
// Print entries with type "mark"
perfEntries = list.getEntriesByType("mark");
for (var i=0; i < perfEntries.length; i++) {
print_perf_entry(perfEntries[i]);
}
});
// subscribe to all performance event types
observe_all.observe({entryTypes: ['frame', 'mark', 'measure', 'navigation', 'resource', 'server']});
var observe_frame = new PerformanceObserver(function(list, obs) {
var perfEntries = list.getEntries();
// Should only have 'frame' entries
for (var i=0; i < perfEntries.length; i++) {
print_perf_entry(perfEntries[i]);
}
});
// subscribe to frame event only
observe_frame.observe({entryTypes: ['frame']});
Specifications
Specification | Status | Comment |
---|---|---|
Performance Timeline Level 2 The definition of 'getEntries()' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论