performance.getEntriesByName('first-contentful-paint')[0] is undefined
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?
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 = () => [];
}
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.