Web/API/LargestContentfulPaint

From Get docs

This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.


The LargestContentfulPaint interface of the Largest Contentful Paint API provides details about the largest image or text paint before user input on a web page. The timing of this paint is a good heuristic for when the main page content is available during load.

Properties

LargestContentfulPaint.element
The element that is the current largest contentful paint.
LargestContentfulPaint.renderTime
The time the element was rendered to the screen. May not be available if the element is a cross-origin image loaded without the Timing-Allow-Origin header.
LargestContentfulPaint.loadTime
The time the element was loaded.
LargestContentfulPaint.size
The intrinsic size of the element returned as the area (width * height).
LargestContentfulPaint.id
The id of the element. This property returns an empty string when there is no id.
LargestContentfulPaint.url
If the element is an image, the request url of the image.

Methods

LargestContentfulPaint.toJSON()
Returns the above properties as JSON.

Examples

The following example shows how to create a PerformanceObserver that listens for largest-contentful-paint entries and logs the LCP value to the console.

This example also demonstrates how to include buffered entries (those that ocurred before observer() was called), which is done by setting the buffered option to true.

Note that in this example data is only sent to the server when the user leaves the tab.

// Catch errors since some browsers throw when using the new `type` option.
// https://bugs.webkit.org/show_bug.cgi?id=209216
try {
  let lcp;

  const po = new PerformanceObserver((entryList) => {
    const entries = entryList.getEntries();
    const lastEntry = entries[entries.length - 1];

    // Update `lcp` to the latest value, using `renderTime` if it's available,
    // otherwise using `loadTime`. (Note: `renderTime` may not be available on
    // image elements loaded cross-origin without the `Timing-Allow-Origin` header.)
    lcp = lastEntry.renderTime || lastEntry.loadTime;
  });

  po.observe({type: 'largest-contentful-paint', buffered: true});

  // Send data to the server.
  addEventListener('visibilitychange', function fn() {
    if (lcp && document.visibilityState === 'hidden') {
      console.log('LCP:', lcp);
      removeEventListener('visibilitychange', fn, true);
    }
  }, true);
} catch (e) {
  // Do nothing if the browser doesn't support this API.
}

Specifications

Specification Status Comment
Largest Contentful PaintThe definition of 'LargestContentfulPaint' in that specification. Editor's Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

LargestContentfulPaint

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

element

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

id

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

loadTime

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

renderTime

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

size

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

toJSON

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

url

Experimental'

Chrome

Full support 77

Edge

Full support 80

Firefox

No support No

IE

No support No

Opera

Full support Yes

Safari

No support No

WebView Android

Full support 77

Chrome Android

Full support 77

Firefox Android

No support No

Opera Android

Full support Yes

Safari iOS

No support No

Samsung Internet Android

Full support 12.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.