性能:eventCounts 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

只读的 performance.eventCounts 属性是一个 EventCounts 映射,其中包含按事件类型分派的事件数量。

并非所有事件类型都已公开。您只能获取由 PerformanceEventTiming 接口支持的事件类型的计数。

一个 EventCounts 映射。(一个只读的 Map,不包含 clear()delete()set() 方法)。

示例

报告事件类型及其计数

如果您想将事件计数发送到您的分析系统,您可能需要实现一个像 sendToEventAnalytics 这样的函数,该函数从 performance.eventCounts 映射中获取事件计数,然后使用 Fetch API 将数据发布到您的端点。

js
// Report all exposed events
for (entry of performance.eventCounts.entries()) {
  const type = entry[0];
  const count = entry[1];
  // sendToEventAnalytics(type, count);
}

// Report a specific event
const clickCount = performance.eventCounts.get("click");
// sendToEventAnalytics("click", clickCount);

// Check if an event count is exposed for a type
const isExposed = performance.eventCounts.has("mousemove"); // false

规范

规范
事件计时 API
# dom-performance-eventcounts

浏览器兼容性

另见