const puppeteer = require("puppeteer"); const START_URL = "https://start.example.com"; // Replace with your start URL const FINAL_URL = "https://end.example.com"; // Replace with your final URL (async () => { const attempts = 100; // Number of runs let totalDuration = 0; // To calculate the average time const results = []; // Store each attempt duration // Launch Puppeteer with your installed Chrome const browser = await puppeteer.launch({ headless: false, // Run in visible mode executablePath: "/path/to/your/chrome", // Optional: Replace with your Chrome path if needed defaultViewport: null, // Use full viewport of your screen }); for (let i = 0; i < attempts; i++) { const startTime = Date.now(); const page = await browser.newPage(); // Clear cookies and cache const client = await page.target().createCDPSession(); await client.send("Network.clearBrowserCookies"); await client.send("Network.clearBrowserCache"); // Open the start URL and wait for the final URL await page.goto(START_URL); await page.waitForFunction( (finalUrl) => window.location.href === finalUrl, {}, FINAL_URL ); const endTime = Date.now(); const duration = endTime - startTime; totalDuration += duration; results.push(duration); console.log(`Attempt ${i + 1}: ${duration}ms`); await page.close(); } // Calculate the average time const averageDuration = totalDuration / attempts; console.log(`\nAverage Time: ${averageDuration}ms`); // Log all attempts console.log("\nIndividual Durations:"); results.forEach((duration, index) => { console.log(`Run ${index + 1}: ${duration}ms`); }); await browser.close(); })();