// The key is the interaction ID.
const eventLatencies = new Map();
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.interactionId > 0) {
const interactionId = entry.interactionId;
if (!eventLatencies.has(interactionId)) {
eventLatencies.set(interactionId, []);
}
eventLatencies.get(interactionId).push(entry.duration);
}
});
// Log the maximum observed event duration for each interaction.
eventLatencies.forEach((durations, interactionId) => {
console.log(interactionId, Math.max(...durations));
});
});
observer.observe({ type: "event", buffered: true });PerformanceEventTiming: interactionId property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.