web-vitals icon indicating copy to clipboard operation
web-vitals copied to clipboard

performance.getEntriesByName('first-contentful-paint')[0] is undefined

Open jamilao opened this issue 4 years ago • 2 comments

While reviewing some of the Web Vitals data that I've gathered over the past few weeks, I noticed that performance.getEntriesByName('first-contentful-paint')[0] is sometimes undefined. I've mainly noticed the issue in Safari browsers (versions 8 through 14), but the getFCP() function is supported according to the README. Should there be a check to ensure the array is not empty?

jamilao avatar Jul 26 '21 22:07 jamilao

getEntriesByName is not supported in safari 10. https://caniuse.com/?search=getEntriesByName

Add below code before web-vitals is OK for me.

if (!window.performance.getEntriesByName) {
    window.performance.getEntriesByName = () => [];
}

lichangwei avatar Jul 31 '21 00:07 lichangwei

What version of this library are you using? A check for window.performance.getEntriesByName was added in version 2.0.1, so if you're using the latest version this shouldn't be an issue.

philipwalton avatar Aug 05 '21 00:08 philipwalton