How to adjust Puppeteer’s settings for better performance?

  1. Increase the timeout settings: By default, Puppeteer has a timeout of 30 seconds for actions like page navigation or element selection. You can increase this timeout value to reduce the likelihood of timeouts during your tests. You can do this by setting the timeout value when launching a new browser instance or page, like this:
const browser = await puppeteer.launch({ timeout: 60000 }); // 60 seconds timeout
  1. Disable images and CSS: Loading images and CSS can significantly slow down the performance of Puppeteer tests. If your tests don't rely on images or CSS, you can disable them to improve performance. You can do this by setting the args option when launching a new browser instance, like this:
const browser = await puppeteer.launch({ args: ['--disable-images', '--disable-css'] });
  1. Use headless mode: Puppeteer supports both headless and non-headless modes. Running tests in headless mode can improve performance since it doesn't render the webpage visually. You can enable headless mode when launching a new browser instance, like this:
const browser = await puppeteer.launch({ headless: true });
  1. Reduce logging: Puppeteer generates a lot of logging output by default, which can slow down the performance of your tests. You can reduce the amount of logging by setting the logLevel option when launching a new browser instance, like this:
const browser = await puppeteer.launch({ logLevel: 'error' });
  1. Use page caching: Caching can help reduce the time it takes to load a webpage in Puppeteer. You can enable caching by setting the args option when launching a new browser instance, like this:
const browser = await puppeteer.launch({ args: ['--disk-cache=true'] });

By adjusting these settings, you can improve the performance of your Puppeteer tests and make them run more efficiently.