To capture and analyze website loading speed with Puppeteer, you can follow these steps:
npm install puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const url = 'https://www.example.com';
await page.goto(url, {waitUntil: 'load'});
const performanceTiming = JSON.parse(
await page.evaluate(() => JSON.stringify(window.performance.timing))
);
const loadTime = performanceTiming.loadEventEnd - performanceTiming.navigationStart;
console.log(`Website ${url} loaded in ${loadTime} ms`);
await browser.close();
})();
node analyze-speed.js
By following these steps, you can easily capture and analyze website loading speed with Puppeteer.