Created
April 29, 2020 17:00
-
-
Save StephenFluin/b0a9cf3e555dca1441f89d4e0db0370d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lcp = await page.evaluate(() => new Promise((resolve, reject) => { | |
try { | |
// Create a variable to hold the latest LCP value (since it can change). | |
let lcp; | |
// Create the PerformanceObserver instance. | |
const po = new PerformanceObserver((entryList) => { | |
const entries = entryList.getEntries(); | |
const lastEntry = entries[entries.length - 1]; | |
lcp = (<any>lastEntry).renderTime || (<any>lastEntry).loadTime; | |
resolve(lcp); | |
po.disconnect(); | |
}); | |
// Observe entries of type `largest-contentful-paint`, including buffered | |
// entries, i.e. entries that occurred before calling `observe()`. | |
po.observe({ type: 'largest-contentful-paint', buffered: true }); | |
} catch (e) { | |
// Do nothing if the browser doesn't support this API. | |
} | |
})); | |
console.log('lcp is',lcp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment