diff --git a/src/utils/index.js b/src/utils/index.js index c6a513119fbfc0060ecdac0d26da1e7490d9bafb..69196ffe8f728239155144cd6a956bcf6243d39c 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 {