The read-only duration
property returns a timestamp that is the duration of the performance entry. The meaning of this property depends on the value of this entry's entryType
.
The read-only duration
property returns a timestamp that is the duration of the performance entry. The meaning of this property depends on the value of this entry's entryType
.
A DOMHighResTimeStamp
representing the duration of the performance entry. If the duration concept doesn't apply for a particular performance metric, a duration of 0
is returned.
The meaning of this property depends on the value of this performance entry's entryType
:
event
The time from the event's startTime
to the next rendering paint (rounded to the nearest 8ms).
first-input
The time from the first input event's startTime
to the next rendering paint (rounded to the nearest 8ms).
longtask
The elapsed time between the start and end of task, with a 1ms granularity.
measure
The duration of the measure.
The difference between the entry's loadEventEnd
and startTime
properties.
resource
The entry's responseEnd
value minus the entry's startTime
value.
For the following entry types, duration
is not applicable, and in this case the value is always 0
:
element
largest-contentful-paint
layout-shift
mark
paint
taskattribution
visibility-state
The following example logs all observed performance entries with a duration
larger than 0
.
js
function perfObserver(list, observer) { list.getEntries().forEach((entry) => { if (entry.duration > 0) { console.log(`${entry.name}'s duration: ${entry.duration}`); } }); } const observer = new PerformanceObserver(perfObserver); observer.observe({ entryTypes: ["measure", "mark", "resource"] });
Specification |
---|
Performance Timeline # dom-performanceentry-duration |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
duration |
28 | 12 | 35 | 10 | 15 | 11 | 4.4 | 28 | 35 | 14 | 11 | 1.5 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/duration