| 173 | } |
| 174 | |
| 175 | function getPerformance() { |
| 176 | const paint = performance |
| 177 | ?.getEntriesByType('paint') |
| 178 | ?.find(({ name }) => name === 'first-contentful-paint') |
| 179 | const nav = performance?.getEntriesByType('navigation')?.[0] as |
| 180 | | PerformanceNavigationTiming |
| 181 | | undefined |
| 182 | return { |
| 183 | firstContentfulPaint: paint ? paint.startTime / 1000 : undefined, |
| 184 | domInteractive: nav ? nav.domInteractive / 1000 : undefined, |
| 185 | domComplete: nav ? nav.domComplete / 1000 : undefined, |
| 186 | render: nav ? (nav.responseEnd - nav.requestStart) / 1000 : undefined, |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function trackScroll() { |
| 191 | // Throttle the calculations to no more than five per second |