PerformanceLongTaskTiming
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
ThePerformanceLongTaskTiming
interface provides information about tasks that occupy the UI thread for 50 milliseconds or more.
In this article
Description
Long tasks that block the main thread for 50ms or more cause, among other issues:
- DelayedTime to interactive (TTI).
- High/variable input latency.
- High/variable event handling latency.
- Janky animations and scrolling.
A long task is any uninterrupted period where the main UI thread is busy for 50ms or longer. Common examples include:
- Long-running event handlers.
- Expensive reflows and other re-renders.
- Work the browser does between different turns of the event loop that exceeds 50 ms.
Long tasks refer to "culprit browsing context container", or "the container" for short, which is the top-level page,<iframe>
,<embed>
or<object>
that the task occurred within.
For tasks that don't occur within the top-level page and for figuring out which container is responsible for the long task, theTaskAttributionTiming
interface provides thecontainerId
,containerName
andcontainerSrc
properties, which may provide more information about the source of the task.
PerformanceLongTaskTiming
inherits fromPerformanceEntry
.
Instance properties
This interface extends the followingPerformanceEntry
properties for long task timing performance entry types by qualifying them as follows:
PerformanceEntry.duration
Read onlyExperimentalReturns a
DOMHighResTimeStamp
representing the elapsed time between the start and end of the task, with a 1ms granularity.PerformanceEntry.entryType
Read onlyExperimentalAlways returns
"longtask"
PerformanceEntry.name
Read onlyExperimentalReturns one of the following strings referring to the browsing context or frame that can be attributed to the long task:
"cross-origin-ancestor"
"cross-origin-descendant"
"cross-origin-unreachable"
"multiple-contexts"
"same-origin-ancestor"
"same-origin-descendant"
"same-origin"
"self"
"unknown"
PerformanceEntry.startTime
Read onlyExperimentalReturns a
DOMHighResTimeStamp
representing the time when the task started.
This interface also supports the following properties:
PerformanceLongTaskTiming.attribution
Read onlyExperimentalReturns a sequence of
TaskAttributionTiming
instances.
Instance methods
PerformanceLongTaskTiming.toJSON()
ExperimentalReturns a JSON representation of the
PerformanceLongTaskTiming
object.
Examples
>Getting long tasks
To get long task timing information, create aPerformanceObserver
instance and then call itsobserve()
method, passing in"longtask"
as the value of thetype
option. You also need to setbuffered
totrue
to get access to long tasks the user agent buffered while constructing the document. ThePerformanceObserver
object's callback will then be called with a list ofPerformanceLongTaskTiming
objects which you can analyze.
const observer = new PerformanceObserver((list) => { list.getEntries().forEach((entry) => { console.log(entry); });});observer.observe({ type: "longtask", buffered: true });
Specifications
Specification |
---|
Long Tasks API> # sec-PerformanceLongTaskTiming> |
Browser compatibility
Loading…