I used npm i puppeteer
as stated in the Documentation
and I\'m getting the following error:
(node:2066) UnhandledPromiseRejectionWarning: Error: Chr
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();
})();
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.
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
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
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
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']
});