PerformanceLongTaskTiming

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The PerformanceLongTaskTiming interface provides information about tasks that occupy the UI thread for 50 milliseconds or more.

Description

Long tasks that block the main thread for 50ms or more cause, among other issues:

  • Delayed Time 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, the TaskAttributionTiming interface provides the containerId, containerName and containerSrc properties, which may provide more information about the source of the task.

PerformanceLongTaskTiming inherits from PerformanceEntry.

PerformanceEntry PerformanceLongTaskTiming

Instance properties

This interface extends the following PerformanceEntry properties for long task timing performance entry types by qualifying them as follows:

PerformanceEntry.duration Read only

Returns a DOMHighResTimeStamp representing the elapsed time between the start and end of the task, with a 1ms granularity.

PerformanceEntry.entryType Read only

Always returns "longtask"

PerformanceEntry.name Read only

Returns 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 only

Returns a DOMHighResTimeStamp representing the time when the task started.

This interface also supports the following properties:

PerformanceLongTaskTiming.attribution Read only

Returns a sequence of TaskAttributionTiming instances.

Instance methods

PerformanceLongTaskTiming.toJSON()

Returns a JSON representation of the PerformanceLongTaskTiming object.

Examples

Getting long tasks

To get long task timing information, create a PerformanceObserver instance and then call its observe() method, passing in "longtask" as the value of the type option. You also need to set buffered to true to get access to long tasks the user agent buffered while constructing the document. The PerformanceObserver object's callback will then be called with a list of PerformanceLongTaskTiming objects which you can analyze.

js
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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
PerformanceLongTaskTiming
Experimental
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1348405
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 58 (Release date: 2017-04-25)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1348405
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 58 (Release date: 2017-04-25)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
attribution
Experimental
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 58 (Release date: 2017-04-25)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 58 (Release date: 2017-04-25)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
toJSON
Experimental
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 58 (Release date: 2017-04-25)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 58 (Release date: 2017-04-25)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also