68

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.

Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32
  • Interesting. I had a similar issue on a previous Ubuntu setup, chromium wasn't downloading. Now, I'm installing on a new server and when I `npm install puppeteer`, it did not show it was downloading Chrome during installation. However, running `node node_modules/puppeteer/install.js` said Chromium was already in `/root/.cache/chrome/linux-1095492` folder. – InfiniteStack Feb 20 '23 at 14:20

16 Answers16

145

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
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
  • 2
    My local modules had `puppeteer-core` instead of `puppeteer` but the solution worked the same. – Mike Smith Apr 28 '21 at 14:38
  • This worked on me for a mac, but I also needed to unset an env var. `unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD && node ./node_modules/puppeteer/install.js` – pxwise Aug 02 '22 at 20:41
50

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

Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32
46

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.

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • That command worked for me, but I didn't set the ignore-scripts to true. I did a straight npm install. Weird! – dearsina Jan 31 '23 at 04:08
  • I had to clean up some disk space and the .cache folder got removed. Running `npn i puppeteer` did not re-run the install script. Running manually dl into the .cache folder, and my project is running again. – James Jul 04 '23 at 00:16
16

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();
    })();
Amr Hussein
  • 161
  • 1
  • 3
6

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']
    });
smoore4
  • 4,520
  • 3
  • 36
  • 55
f1vlad
  • 227
  • 3
  • 12
5

In my case, it worked after deleting node_modules folder and package-lock.json file and running npm install again.

Vikash Gupta
  • 179
  • 2
  • 10
3

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

Roy.B
  • 2,076
  • 14
  • 23
3

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.

Hamid Shoja
  • 3,838
  • 4
  • 30
  • 45
2

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
});
Syscall
  • 19,327
  • 10
  • 37
  • 52
  • "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" so you need to make sure the Chromium version you dl will work with your version of Puppeteer. – James Jul 04 '23 at 00:12
1

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

Rahul9989
  • 21
  • 1
0

On Windows works installing as global

npm i puppeteer --g
0

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

Mohamed
  • 425
  • 4
  • 14
0

I just delete the PUPPETEER_SKIP_CHROMIUM_DOWNLOAD variable from the Dockerfile and that worked for me

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

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.

  1. Create your project directory where puppeteer should be installed

  2. Go inside this directory.

    If you are root, change to the normal user of the system.

  3. 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.

  4. Install puppeteer:

    Here you can basically hit enter until the init is done.

    npm init
    
    npm i puppeteer
    
  5. On Unix, make sure all the necessary dependencies are installed.

    You can find the list on the Troubleshooting page.

  6. 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'
     });
    
drake7
  • 952
  • 7
  • 20
0

Use executablePath()

import { executablePath } from "puppeteer";


const options: PuppeteerLaunchOptions = {
 ...
 executablePath: executablePath(),
};

await puppeteer.launch(options);

Remove from Dockerfile

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
Craig
  • 11
  • 1
0

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

MarcusOtter
  • 1,095
  • 10
  • 19