Create a PerformanceObserver for paint timing (FCP)
Observes First Contentful Paint using the Performance API. Falls back gracefully in non-browser environments.
Function to call when FCP is detected
Cleanup function to disconnect observer
const cleanup = observeFCP((entry) => { console.log('FCP:', entry.value, 'ms'); console.log('Rating:', entry.rating);});// Later, to stop observing:cleanup(); Copy
const cleanup = observeFCP((entry) => { console.log('FCP:', entry.value, 'ms'); console.log('Rating:', entry.rating);});// Later, to stop observing:cleanup();
Create a PerformanceObserver for paint timing (FCP)
Observes First Contentful Paint using the Performance API. Falls back gracefully in non-browser environments.