'how do you install and run puppeteer for firefox
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 [email protected]: 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
[email protected] 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
Solution 1:[1]
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.
Solution 2:[2]
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);
})();
Solution 3:[3]
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
Solution 4:[4]
You can also try to delete puppeteer from node_modules folder and
npm install
worked for me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henrik |
| Solution 2 | |
| Solution 3 | Arthur Lomakin |
| Solution 4 | SHIVAM TIWARI |
