17

Hi I am doing some web automation. I am trying to open a url and I am getting a data URL error in chrome console so I am moving to firefox console to get around the no data urls opening in the chrome console issue. The problem is "npm install puppeteer-firefox" is not working to install puppeteer for firefox. How can I install puppeteer for firefox and include it in the code so I can use it?

Code not working in chrome because of data url error

const url = await page.evaluate(async () => {

    
        document.querySelector('.n3VNCb').src;
        
    });
    
    url.toString();
    
    await page.goto(url);

What I typed into node.js command prompt to install puppeteer firefox. This did not work

npm i puppeteer-firefox

Error I received from the node.js command prompt

npm WARN deprecated puppeteer-firefox@0.5.1: Firefox support is gradually transitioning to the puppeteer package. As of puppeteer v2.1.0 you can interact with Firefox Nightly. The puppeteer-firefox > package will remain available until the transition is complete, but it is no longer actively maintained. For more information visit https://wiki.mozilla.org/Remote

puppeteer-firefox@0.5.1 install C:\Users\user\Desktop\filename\filename\node_modules\puppeteer-firefox node install.js

ERROR: Failed to download Firefox rv0.0.1! Error: Download failed: server returned code 404. URL: https://github.com/puppeteer/juggler/releases/download/v0.0.1/firefox-win64.zip

I also tried these as an error said to do and they did not work

(node:14348) UnhandledPromiseRejectionWarning: Error: Could not find browser revision latest. Run "PUPPETEER_PRODUCT=firefox npm install" or "PUPPETEER_PRODUCT=firefox yarn install" to download a supported Firefox browser binary.

PUPPETEER_PRODUCT=firefox npm install

PUPPETEER_PRODUCT=firefox yarn install

Roboman Robo
  • 599
  • 2
  • 5
  • 16

5 Answers5

21

I had a similar issue, the command you have to run is actually the following:

PUPPETEER_PRODUCT=firefox npm i puppeteer

Source : https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#puppeteerlaunchoptions

Calahad
  • 1,408
  • 14
  • 22
  • Thanks . I have been using playwright (made by the puppeteer team but they moved to Microsoft from google so I guess they had to change the name). Playwright has built in firefox support, and it work well enough. I ended up using chromium with puppeteer (not a typo). I would say to use playwright for firefox support. – Roboman Robo Aug 29 '20 at 08:14
  • Thanks, @Calahad. Didn't test because I already have what I need now with puppeteer, but I think your answer should work. Thank You – Roboman Robo Aug 29 '20 at 08:15
13

Please don't use the puppeteer-firefox package anymore. It has been deprecated. Instead just install puppeteer with Firefox as selected product. Here an example from the puppeteer repository that shows how to launch Firefox from your test script.

Henrik
  • 249
  • 1
  • 6
6

type the command below to locate your browser

whereis firefox
OR
whereis google-chrome

I used chrome so, mine was. You can replace it with firefox path.

/usr/bin/google-chrome

hence, the final step.

export PUPPETEER_EXECUTABLE_PATH='/usr/bin/google-chrome'

that's it :)

Note:

You should add this variable to your shell configuration like ~/.bashrc or ~/.zshrc otherwise after the restart, you will lose this variable value. Or more globally in /etc/environment

UPDATE:

The above answer worked for me in the past but the following is the most appropriate solution, still working for firefox.

To install firefox for the puppeteer.

npm i puppeteer-firefox

Code example tested and working for both chrome and firefox.

const puppeteerChrome = require('puppeteer');
const puppeteerFirefox = require('puppeteer-firefox');

(async () => {

    const test = async browser => {
        const page = await browser.newPage();
        await page.setViewport({
            width: 1280,
            height: 800
        });
        await page.goto('https://www.bbc.com/news');   
        await page.hover('#nw-c-most-read-heading__title');
        await page.screenshot({ path: 'bcc-most-read.png' })
        
        await browser.close();
    }

    const chrome = await puppeteerChrome.launch({
        headless: false,
        slowMo: 50
    });
    await test(chrome);

    const firefox = await puppeteerFirefox.launch({
        headless: false,
        slowMo: 50
    });
    await test(firefox);

})();
zarpio
  • 10,380
  • 8
  • 58
  • 71
1

Personally had a problem with Puppeteer. Can't install it on ubuntu. Just empty .local-firefox. Playwright has webkit, chromium and firefox inside it. No problems at all. It just works

-1

You can also try to delete puppeteer from node_modules folder and

npm install

worked for me