How to run Puppeteer with Firefox instead of Chrome?

To run Puppeteer with Firefox instead of Chrome, you can follow these steps:

  1. First, make sure you have Puppeteer installed. You can install Puppeteer using npm by running the following command:
npm install puppeteer
  1. Next, you will need to install the puppeteer-firefox package, which enables Puppeteer to work with Firefox. You can install it using the following command:
npm install puppeteer-firefox
  1. Now, you can create a new Puppeteer script and configure it to use Firefox instead of Chrome. Here is an example script that uses Firefox:
const puppeteer = require('puppeteer-firefox'); (async () => { const browser = await puppeteer.launch({ executablePath: '/path/to/firefox-bin', headless: false // Set to true for headless mode }); const page = await browser.newPage(); await page.goto('https://example.com'); // Add your Puppeteer code here await browser.close(); })();

In the puppeteer.launch() method, you can specify the path to your Firefox binary using the executablePath option. Make sure to replace /path/to/firefox-bin with the correct path on your system.

  1. Run your Puppeteer script using Node.js:
node your-script.js

Your Puppeteer script should now be running with Firefox instead of Chrome.