Skip to content

Instantly share code, notes, and snippets.

@bgrewell
Last active January 9, 2020 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrewell/6cdb55708654ed0fc1a94cb597649743 to your computer and use it in GitHub Desktop.
Save bgrewell/6cdb55708654ed0fc1a94cb597649743 to your computer and use it in GitHub Desktop.
Example for getting performance timing from chrome
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