Performance API
The lastInputTime read-only property of the LayoutShift interface returns the time of the most recent excluding input or 0 if no excluding input has occurred.
Layout shifts are only bad if the user wasn't expecting them. Layout shift metrics like CLS exclude shifts that occurred soon after certain user interactions. These interactions are called excluding inputs. Excluding inputs are:
- Any events which signal a user's active interaction with the document: (
mousedown,keydown, andpointerdown) - Any events which directly changes the size of the viewport.
changeevents.
The mousemove and pointermove events are not excluding inputs.
Value
A DOMHighResTimeStamp indicating the most recent excluding input time or 0 if no excluding input has occurred.
Examples
Logging last input times
Log excluding input times if excluding input has occurred.
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (entry.lastInputTime) {
console.log(entry.lastInputTime);
}
});
});
observer.observe({ type: "layout-shift", buffered: true });
Specifications
Browser compatibility
See also
- LayoutShift.hadRecentInput
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
