element-timing icon indicating copy to clipboard operation
element-timing copied to clipboard

Clarify Element Timing's handling of pseudo-elements

Open brendankenny opened this issue 3 years ago • 6 comments

The spec doesn't appear to say how Element Timing for pseudo-elements should be handled. A surprising number of sites put large content in pseudo-elements, so explicit support would be helpful for performance measurements and downstream specs like LCP.

Current browser behavior:

Chrome appears to be the only browser where support (or lack) is observable, but please correct me if I'm missing an entryType somewhere.

  • In Chrome, Element Timing will include timing for images in a background-image on a pseudo-element (example using a background image in ::after). The element property will be set to the originating element, but the intersectionRect, naturalWidth, naturalHeight, and url will all be for the actual image painted in the pseudo-element.

    This is perhaps the best that can be done, since it's not possible to have a JS reference to the pseudo-element itself. The image information in the entry is usually enough to figure out what exactly is being referred to, but an additional annotation somewhere to explicitly mark the entry as referring to a pseudo-element could be helpful for automated tools to know where to look.

  • Again in Chrome, Element Timing will not include timing for images in a more-or-less identical page but using content in a pseudo-element to add an image (example using content in ::after). As a result, the smaller text is determined to be the LCP element instead of the larger image.

brendankenny avatar Jan 19 '23 20:01 brendankenny

It would be good to align this with Paint Timing, which specifically includes pseudo elements (regardless of the way that their content is declared)

clelland avatar Sep 22 '23 19:09 clelland