Reputation: 3027
I used npm i puppeteer
as stated in the Documentation
and I'm getting the following error:
(node:2066) UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install" at Launcher.launch
when im trying this example (also from the docs):
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Also in the documentation:
Note: When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API.
Any help would be appreciated.
Upvotes: 75
Views: 120286
Reputation: 2990
I only managed to fix the issue by manually installing Chromium after much searching and trying most of the suggestions:
node node_modules/puppeteer/install.js
To ensure the correct installation of the newer version, I recommend checking the directory node_modules/puppeteer. If you find that the installation file's extension is .mjs, please use it accordingly.
node node_modules/puppeteer/install.mjs
Upvotes: 157
Reputation: 1273
None of the other answers worked for me.
It turns out that the Chromium download URL (https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html) can be blocked if you are sitting on a VPN. If this is the case, the installation script (node_modules/puppeteer/install.js
) will say that it successfully downloaded to ~/.cache/puppeteer/chrome/<version>
but all it does it create an empty folder.
The solution for me was to switch to a different location with my VPN.
Here is the status for this issue in the Puppeteer repository: https://github.com/puppeteer/puppeteer/issues/10013
Upvotes: 0
Reputation: 19
Use executablePath()
import { executablePath } from "puppeteer";
const options: PuppeteerLaunchOptions = {
...
executablePath: executablePath(),
};
await puppeteer.launch(options);
Remove from Dockerfile
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
Upvotes: 0
Reputation: 1224
The 3rd point in Amr Hussein's answer helped me to solve a similar Problem where I got the following error, whenever I executed my script outside the project directory:
throw new Error(`Could not find Chromium (rev. ${this.puppeteer.browserRevision})
Error: Could not find Chromium (rev. 1083080).
I will use that in my last step.
But let's start at the very beginning:
If you install puppeteer
, Chrome will be automatically downloaded. But it is recommended that you change the default location of Chrome with a Configuration file.
Create your project directory where puppeteer
should be installed
Go inside this directory.
If you are root
, change to the normal user of the system.
As recommended in the documentation, create a file named .puppeteerrc.cjs
and paste in the following code:
const {join} = require('path');
/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};
This will change the default location of Chrome to your project directory.
Now Chrome will be stored inside the project directory in the .cache
directory.
Install puppeteer
:
Here you can basically hit enter
until the init is done.
npm init
npm i puppeteer
On Unix, make sure all the necessary dependencies are installed.
You can find the list on the Troubleshooting page.
Find Chrome
inside the .cache
directory of your project directory and figure out the full path.
Add the executablePath:
of the Chrome executable to your script:
const browser = await puppeteer.launch({
executablePath: '/home/drake/my_puppeteer_project/.cache/puppeteer/chrome/linux-1083080/chrome-linux/chrome'
});
Upvotes: 0
Reputation: 1
I just delete the PUPPETEER_SKIP_CHROMIUM_DOWNLOAD
variable from the Dockerfile and that worked for me
Upvotes: 0
Reputation: 469
Here is how I solved it
const browser = await puppeteer.launch({
headless: true,
ignoreDefaultArgs: ['--disable-extensions'], // this made it work for now
});
By simply having ignoreDefaultArgs: ['--disable-extensions']
done the trick
Source: Troubleshoot
Upvotes: 0
Reputation: 4778
After couple of hours googling and reading many comments and discussions, trying several approach finally I resolved the problem with this solution.
OS: Windows 10
node: 14.16.1
puppeteer: 7.0.1
I saw in the node_modules/puppeteer/
folder and found that there isn't any .local-chromium
folder so I created this path manually
node_modules/puppeteer/.local-chromium/win64-<your_chrome_version>/chrome-win
Then I downloaded the chromium browser from this link (your_chrome_version) and so copied it to the path so that you need to see the chrome.exe in this url
node_modules/puppeteer/.local-chromium/win64-<your_chrome_version>/chrome-win/chrome.exe
That's it. it worked for me.
Upvotes: 3
Reputation: 89
This is because you don't have Chrome installed on your system.
For installing Chrome
sudo apt install -y chromium-browser
then after that add an executable path.
const browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
headless: false
});
Upvotes: 2
Reputation: 43979
By default, the puppeteer
module will run its install script (node install.js
). However, in my case, I enabled ignore-scripts=true
in my ~/.npmrc
file, so it was never executed.
In that case, you have to run the command yourself:
node node_modules/puppeteer/install.js
To check: node_modules/puppeteer/.local-chromium/linux-<your_chrome_version>/
should exist now.
Upvotes: 47
Reputation: 277
Confirming solutions presented here almost work. Here's my setup. Ubuntu 16.
Install chromium browser from command line then:
const browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium-browser",
args: ['--no-sandbox']
});
Upvotes: 7
Reputation: 169
In my case, it worked after deleting node_modules folder and package-lock.json file and running npm install again.
Upvotes: 4
Reputation: 21
If someone still facing this problem again. Then goto node_modules folder then into puppeteer and in lib where you find launch.js open the same file and search for executablepath then change its null value to your chrome or chromium desired path.
For me the path as follows :
/home/Nightwing/node_modules/puppeteer/Launcher.js
Upvotes: 1
Reputation: 161
for linux:
1- you must have installed chromium browser using this command :
$sudo apt install -y chromium-browser
2- you have to get the excutable path of chromium using this command :
$which chromium-browser
3-put the executable path as an argument to the launch function :
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
headless: false
});
const page = await browser.newPage();
await page.goto('https://google.com');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
Upvotes: 16
Reputation: 3027
After many attempts I finally found the answer here:
sudo npm install puppeteer --unsafe-perm=true --allow-root
As @vsync pointed out, this only works for linux
Upvotes: 54
Reputation: 2106
I solved it like this:
const browser = await puppeteer.launch({ executablePath: "./node_modules/puppeteer/.local-chromium/win64-656675/chrome-win/chrome.exe"});
note the win64-656675 in the path, if you're on a different operating system you will need to point to the appropriate folder.
puppeteer version: 1.16.0
Upvotes: 3