Last active
January 9, 2020 21:59
-
-
Save bgrewell/6cdb55708654ed0fc1a94cb597649743 to your computer and use it in GitHub Desktop.
Example for getting performance timing from chrome
This file contains hidden or 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
const puppeteer = require('puppeteer'); | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function requestPageTiming(url) { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto("https://www.amazon.com"); | |
const performanceTiming = JSON.parse( | |
await page.evaluate(() => JSON.stringify(window.performance.timing)) | |
); | |
await browser.close(); | |
return performanceTiming; | |
} | |
async function runTests() { | |
var urls = ["https://www.amazon.com", "https://www.google.com", "https://www.msn.com", "https://www.yahoo.com"]; | |
for (const url of urls) { | |
await requestPageTiming("https://www.amazon.com").then((timingResult) => { | |
console.log(timingResult); | |
}) | |
} | |
} | |
runTests(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment