From c6f9c22c5296d8cdb770d67a373e20c4a2766868 Mon Sep 17 00:00:00 2001 From: qq_38870145 Date: Sat, 9 Mar 2024 20:18:00 +0800 Subject: [PATCH] Sat Mar 9 20:18:00 CST 2024 inscode --- src/utils/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils/index.js b/src/utils/index.js index c6a5131..69196ff 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -34,6 +34,25 @@ class ListenDomChange { // 之后,可停止观察 observer.disconnect(); } + + getPerformance() { + // 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), + ); + } } export { -- GitLab