How to Run Puppeteer with Firefox Instead of Chrome
In this article
Puppeteer normally launches Chrome, but you can make it use Firefox instead. This lets you test against Firefox's rendering engine while keeping the same Puppeteer API. You'll need Node.js installed and a project with Puppeteer already set up. The process involves installing the Firefox-compatible version of Puppeteer and specifying Firefox as the browser when launching.
What You'll Need
- Node.js (version 14 or higher) installed on your system
- An existing Node.js project with a package.json file
- Basic familiarity with the command line and JavaScript
- Internet access to download the Firefox browser binary
Step-by-Step
- Check your current Puppeteer version. Run
npm list puppeteerin your project directory to see what's installed. If you're using Puppeteer v22 or later, you're on a version that supports Firefox. If not, you'll need to update. - Install the latest Puppeteer. In your terminal, run
npm install puppeteer@latest. This ensures you have a version that can control Firefox. The installation will also download the latest Chrome for Testing, but that's fine—you'll just ignore it. - Install the Firefox browser for Puppeteer. Run
npx puppeteer browsers install firefox. This downloads a compatible Firefox build into Puppeteer's cache. It may take a few minutes depending on your internet speed. - Update your launch code. In your JavaScript file where you launch Puppeteer, change the
puppeteer.launch()call to include theproductoption. For example:
If you're usingconst browser = await puppeteer.launch({ product: 'firefox' });puppeteer-core, you'll also need to specify the executable path to the Firefox binary you just downloaded. - Run your script. Execute your Puppeteer script as usual. Puppeteer will now launch Firefox instead of Chrome. You can verify by checking the browser's user agent or by opening the browser in headful mode (set
headless: false) to see the Firefox window. - Handle Firefox-specific differences. Some Puppeteer methods may behave differently in Firefox. For example,
page.pdf()is not supported in Firefox. Test your scripts and adjust them as needed. - Use environment variables (optional). If you want to switch between browsers easily, you can set the
PUPPETEER_PRODUCTenvironment variable tofirefoxbefore running your script. This makes Puppeteer default to Firefox without changing your code.
Common Mistakes
- Using an old Puppeteer version. Puppeteer versions before v22 do not support Firefox. Always update to the latest version.
- Forgetting to install the Firefox browser. Running
npx puppeteer browsers install firefoxis essential. Without it, Puppeteer will fail to find the Firefox executable. - Specifying the product but not the executable path. When using
puppeteer-core, you must provide the path to the Firefox binary explicitly. UseexecutablePath: '/path/to/firefox'in the launch options. - Assuming all features work the same. Firefox support is not identical to Chrome. Features like PDF generation, some network interception, and certain emulation options may not work.
- Not clearing the Puppeteer cache. If you've previously used an older version, the cache might be corrupted. Delete the
~/.cache/puppeteerdirectory and reinstall.
Tips
- Use
headless: truefor CI environments to avoid opening a visible browser window. Firefox's headless mode works well for most tasks. - To see which Firefox version Puppeteer downloaded, run
npx puppeteer browsers list. - If you need to run tests in both browsers, consider using a helper function that reads an environment variable to decide which product to launch.
- Keep your Puppeteer version updated regularly, as Firefox support improves with each release.
- For debugging, set
headless: falseand addslowMo: 100to slow down operations so you can see what's happening.
Troubleshooting
- Error: "Could not find Firefox binary." This means the Firefox browser isn't installed. Run
npx puppeteer browsers install firefoxand try again. If it still fails, manually download Firefox and set theexecutablePathin your launch options. - Script hangs or times out. Firefox may be slower to start than Chrome. Increase the
timeoutoption inlaunch()(e.g.,timeout: 60000). Also check that your system has enough memory. - Page doesn't render correctly. Some CSS features behave differently in Firefox. Use the browser's devtools (in headful mode) to inspect the page and adjust your selectors or wait conditions.
- Puppeteer launches Chrome anyway. Ensure you've passed
product: 'firefox'in the launch options. If you're using environment variables, make surePUPPETEER_PRODUCTis set correctly before the script starts. - Error: "Firefox is not supported in this version of Puppeteer." Your Puppeteer version is too old. Update to the latest version with
npm install puppeteer@latest.
Frequently Asked Questions
Can I run Puppeteer with Firefox and Chrome at the same time?
Yes, you can launch multiple browser instances in the same script. Just call puppeteer.launch() twice, once with product: 'firefox' and once with the default Chrome. Each will run independently.
Does Firefox support headless mode in Puppeteer?
Yes, Firefox supports headless mode. Set headless: true in the launch options. It works for most automation tasks, though some advanced features may have limitations.
Can I use puppeteer-core with Firefox?
Yes, but you must provide the executablePath to a Firefox binary. You can download one manually or use npx puppeteer browsers install firefox to get a compatible version.
Why would I want to use Firefox instead of Chrome?
To test your website or app in a different browser engine. This helps catch compatibility issues and ensures your code works for Firefox users. It's also useful if you need to automate a specific Firefox-only feature.
Is Puppeteer's Firefox support as complete as Chrome's?
No, it's not. Firefox support is still in development. Some features like page.pdf(), certain network interception methods, and some emulation options are not available. Check the Puppeteer documentation for the current status.
Do I need to install Firefox separately?
No, Puppeteer can download and manage its own Firefox binary. Just run npx puppeteer browsers install firefox and it will be cached for your project. If you prefer, you can also use a system-installed Firefox by specifying the executable path.