EventCounts

Baseline 2025
Newly available

Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Giao diện EventCounts của Performance API cung cấp số lượng sự kiện đã được gửi cho mỗi loại sự kiện.

Instance EventCountsđối tượng giống Map chỉ đọc, trong đó mỗi khóa là chuỗi tên cho một loại sự kiện, và giá trị tương ứng là số nguyên cho biết số lượng sự kiện đã được gửi cho loại sự kiện đó.

Hàm khởi tạo

Giao diện này không có hàm khởi tạo. Thông thường bạn nhận được instance của đối tượng này thông qua thuộc tính performance.eventCounts.

Thuộc tính phiên bản

size

Xem Map.prototype.size để biết chi tiết.

Phương thức phiên bản

entries()

Xem Map.prototype.entries() để biết chi tiết.

forEach()

Xem Map.prototype.forEach() để biết chi tiết.

get()

Xem Map.prototype.get() để biết chi tiết.

has()

Xem Map.prototype.has() để biết chi tiết.

keys()

Xem Map.prototype.keys() để biết chi tiết.

values()

Xem Map.prototype.values() để biết chi tiết.

Ví dụ

Làm việc với EventCount maps

Dưới đây là một số ví dụ để lấy thông tin từ map EventCounts. Lưu ý rằng map là chỉ đọc và các phương thức clear(), delete()set() không có sẵn.

js
for (entry of performance.eventCounts.entries()) {
  const type = entry[0];
  const count = entry[1];
}

const clickCount = performance.eventCounts.get("click");

const isExposed = performance.eventCounts.has("mousemove");
const exposedEventsCount = performance.eventCounts.size;
const exposedEventsList = [...performance.eventCounts.keys()];

Thông số kỹ thuật

Specification
Event Timing API
# sec-event-counts

Tương thích trình duyệt

Xem thêm