const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
console.log(
`The time to ${entry.name} was ${entry.startTime} milliseconds.`,
);
// Logs "The time to first-paint was 386.7999999523163 milliseconds."
// Logs "The time to first-contentful-paint was 400.6999999284744 milliseconds."
});
});
observer.observe({ type: "paint", buffered: true });PerformancePaintTiming / notebook
PerformancePaintTiming
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const entries = performance.getEntriesByType("paint");
entries.forEach((entry) => {
console.log(`The time to ${entry.name} was ${entry.startTime} milliseconds.`);
// Logs "The time to first-paint was 386.7999999523163 milliseconds."
// Logs "The time to first-contentful-paint was 400.6999999284744 milliseconds."
});const entries = performance.getEntriesByType("paint");
entries.forEach((entry) => {
if (entry.presentationTime) {
console.log(
"paintTime:",
entry.paintTime,
"presentationTime:",
entry.presentationTime,
);
} else if (entry.paintTime) {
console.log("paintTime:", entry.paintTime);
} else {
console.log("loadTime", entry.loadTime);
}
});