function pagePrerendered() {
return (
document.prerendering ||
self.performance?.getEntriesByType?.("navigation")[0]?.activationStart > 0
);
}PerformanceNavigationTiming: activationStart property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// Time to when activation occurred
let activationStart =
performance.getEntriesByType("navigation")[0].activationStart;
// Time to first paint
let firstPaint = performance.getEntriesByName("first-paint")[0].startTime;
// Time to first contentful paint
let firstContentfulPaint = performance.getEntriesByName(
"first-contentful-paint",
)[0].startTime;
console.log(`time to first paint: ${firstPaint - activationStart}`);
console.log(
`time to first-contentful-paint: ${firstContentfulPaint - activationStart}`,
);