user23634623
user23634623

Reputation: 161

How to install Firefox for Puppeteer?

I've been trying to install firefox for puppeteer for a while, the docs says to run the next command:

PUPPETEER_PRODUCT=firefox npm i puppeteer

But I can't understand where to run it? I've tried

npm config set puppeteer_product firefox

Which downloads the Nightly package but then when trying to run puppeteer I get the next error:

(node:27840) UnhandledPromiseRejectionWarning: Error: Could not find browser revision 782078. Run "PUPPETEER_PRODUCT=firefox n
pm install" or "PUPPETEER_PRODUCT=firefox yarn install" to download a supported Firefox browser binary.

Can anybody help me?

Upvotes: 4

Views: 6455

Answers (2)

protoplan
protoplan

Reputation: 153

This worked for me:

  1. Delete the puppeteer folder from node_modules. This is to force puppeteer to be reinstalled with the firefox binary in step 2.

  2. Run the following commands sequentially in Powershell (if you're on Windows):

    set PUPPETEER_PRODUCT=firefox

    npm i puppeteer

If you're using another OS I think the idea is just to set PUPPETEER_PRODUCT=firefox as a global environment variable before reinstalling puppeteer so it knows to download firefox when it installs.

Upvotes: 0

theDavidBarton
theDavidBarton

Reputation: 8861

Once you've correctly enabled Firefox for puppeteer with:

either npm

PUPPETEER_PRODUCT=firefox npm install puppeteer

or yarn:

PUPPETEER_PRODUCT=firefox yarn add puppeteer

Then you need to set the product option of puppeteer.launch to 'firefox':

const browser = await puppeteer.launch({ product: 'firefox' })

Upvotes: 1

Related Questions