Reputation: 6039
This Meteor code uses "puppeteer 8.0.0", "puppeteer-core 10.0.0", puppeteer-extra 3.1.18" and "puppeteer-extra-plugin-stealth 2.7.8", It gives this error:
Error: Could not find expected browser (chrome) locally. Run
npm install
to download the correct Chromium revision (884014).
Tried "npm install" for no avail. Reading up online, tried removing "puppeteer-core": "^10.0.0" from package.json dependencies for no avail.
Any help is much appriciated. Thanks
const puppeteer = require('puppeteer-extra');
const nameH = require('./NameH');
const puppeteerOptions = {
headless: true,
ignoreHTTPSErrors: true,
args: ['--no-sandbox', '--single-process', '--no-zygote', '--disable-setuid-sandbox']
}
let browser;
let pageNameH;
const init = async () => {
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
console.log('1') //>>>>>>>>>>>> Prints 1
puppeteer.use(StealthPlugin());
console.log('2') //>>>>>>>>>>>> Prints 2
browser = await puppeteer.launch(puppeteerOptions);
console.log('3') //>>>>>>>>> DID NOT PRINT <<<<<<<<<<<<<<<
pageNameH = await browser.newPage();
console.log('4')
await pageNameH.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36');
await pageNameH.setViewport({ width: 1366, height: 768 });
await pageNameH.setRequestInterception(true);
blockResources(pageNameH);
}
const blockResources = page => {
page.on('request', (req) => {
if (req.resourceType() == 'stylesheet' || req.resourceType() == 'font' || req.resourceType() == 'image') {
req.abort();
}
else {
req.continue();
}
});
}
export const abc = async (nm, loc) => {
try {
console.log('name try') //>>>>>>>>>>>> Prints "name try"
if (!(browser && pageNameH))
await init();
//use "required" nameh here
} catch (error) { // print the error <<<<<<<<<<<<<<<<<<<<<<<<<
console.log("Could not launch Puppeteer or open a new page.\n" + error);
if (browser && browser.close === 'function') await browser.close();
}
}
// included in package.json
"dependencies": {
"@babel/runtime": "^7.11.2",
"axios": "^0.21.1",
"check": "^1.0.0",
"cheerio": "^1.0.0-rc.6",
"jquery": "^3.5.1",
"meteor-node-stubs": "^1.0.1",
"nightmare": "^3.0.2",
"pending-xhr-puppeteer": "^2.3.3",
"puppeteer": "^8.0.0",
"puppeteer-core": "^10.0.0",
"puppeteer-extra": "^3.1.18",
"puppeteer-extra-plugin-adblocker": "^2.11.11",
"puppeteer-extra-plugin-block-resources": "^2.2.9",
"puppeteer-extra-plugin-stealth": "^2.7.8"
},
Upvotes: 53
Views: 106798
Reputation: 861
trivikr's solution in the issue "What's the recommended way for installing Chromium on AL2023?" fixed it for me, I had to install it manually on Amazon Linux 2023:
One solution which worked for me it to install Chromium directly from RPM
$ export BROWSERS_SRC_DIR="/usr/src/browsers" && mkdir -p $BROWSERS_SRC_DIR $ curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm \ --output $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm $ yum install -y -q $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm $ /usr/bin/google-chrome-stable --version
Upvotes: -1
Reputation: 2497
In my case, the issue was solved by installing a specific version of chrome. These were my error logs:
Error: Could not find Chrome (ver. 123.0.6312.122). This can occur if either
1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
...
I solved the problem by installing the version from logs:
npx puppeteer browsers install [email protected]
Upvotes: 2
Reputation: 5844
I'm using Volta and when I installed Puppeteer, I had accidentally used Node v10.16.0 with npm 6.9.0 and it apparently couldn't install Chromium.
Here's how I fixed it:
volta pin [email protected]
rm -rf node_modules
npm install puppeteer
Now I can see Chromium in ~/.cache/puppeteer/
and I can run Puppeteer in my project.
Apparently, older Node versions interfere with the install script.
Upvotes: 0
Reputation: 1010
puppeteer-extra
does not include chromium
.
(chromium is a headless version of chrome browser)
you need to install puppeteer
package
npm install puppeteer
or just simple add executablePath
if you don't want to install chromium (I assume you have Chrome browser in your system
const CHROME_EXECUTALBE_PATH = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
const browser = await puppeteer.launch({
executablePath: CHROME_EXECUTALBE_PATH,
headless: true
});
to get the path, open your browse, type chrome://version/
Upvotes: 0
Reputation: 798
For me the issue was that I ran npm install although I shouldn't have. Just deleted the node_modules folder and then ran again - now worked
Upvotes: 0
Reputation: 1139
may be you can try this, it works for me on linux(centOS), puppeteer(10.2.0).
cd ./node_modules/puppeteer
npm run install
If that fails, you can also try running:
cd ./node_modules/puppeteer
npm install
This will download the chromium to ./node_modules/puppeteer/.local-chromium
Upvotes: 113
Reputation: 1145
If you are using puppeteer in AWS SAM and you don't have puppeteer
in dependencies, you can install the same in puppeteer-core
using
node node_modules/puppeteer/install.js
For this setup to work you will have to add chrome-aws-lambda
in the devDependencies
.
"devDependencies": {
"chrome-aws-lambda": "^10.1.0"
}
Also before you take it to production don't forget to add the layer in your template.yaml
file:
Layers:
- !Sub 'arn:aws:lambda:ap-south-1:764866452798:layer:chrome-aws-lambda:25'
Upvotes: 0
Reputation: 11
I was having this error too and I noticed that I started getting such an error after updating my node from my Dockerfile to version ^16 (my puppeteer is in a container). How did I solve it? I downgraded my node from Dockerfile to version 12. Hope this resolves it...
OBS: I use Ubuntu 21.04 in machine.
EDIT ------
In newest versions of node, you need to go in ./node_modules/puppeteer and run command npm install, then the correct packages will be installed. I'm using that solution.
Upvotes: 1
Reputation: 261
Fixed it by running this command to install chromium manually.
node node_modules/puppeteer/install.js
Upvotes: 25
Reputation: 3530
You may need to install some dependencies depending on your OS. Check Puppeteer's Troubleshooting page for more details.
Upvotes: 0
Reputation: 2545
I used the installed version on my pc (maybe not what you're looking for)
const browser = await puppeteer.launch({headless:false, executablePath:
'C:/Program Files/.../chrome.exe' });
Upvotes: 0
Reputation: 2343
Throwing my answer in, in hopes that it helps someone not waste their entire evening like I did.
I was writing a Typescript server that used Puppeteer, and I'm using ESBuild to transpile from TS to JS. In the build step, esbuild was trying to bundle everything into one file, but I had to instruct it to preserve the Puppeteer import from node_modules.
I did this by marking puppeteer
as external. See docs here.
Since npm i
downloads a compatible version of chromium to the node_modules folder, once I preserved this import, it was able to find Chromium in the node_modules folder.
My build file looks like:
require("esbuild").buildSync({
entryPoints: ["src/index.ts"],
outdir: "build",
bundle: true,
platform: "node",
target: "node16",
external: ["puppeteer"],
});
And I run it with node prod-build.js
.
Now in my code, I can just call launch!
const browser = await puppeteer.launch()
Upvotes: 4
Reputation: 5061
I had the same issue. What worked for me was to specify as the executablePath
Puppeteer launch option the fullpath to the local chromium used by Puppeteer.
Something like this:
const launchOptions = {
// other options (headless, args, etc)
executablePath: '/home/jack/repos/my-repo/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome'
}
As noted in another answer, it seems that also referencing a chromium local binary would work, but I think it's a worse solution, since Puppeteer is guaranteed to work only with the local bundled version of Chromium.
Upvotes: 4
Reputation: 71
if you are testing locally, make sure you have puppeteer installed as dev dependencies. specifically
npm install puppeteer --save-dev
https://github.com/alixaxel/chrome-aws-lambda/wiki/HOWTO:-Local-Development#workaround
this approach allows us to rely on puppeteer for local development and puppeteer-core for production deployments.
Upvotes: 7
Reputation: 121
I had the same problem. I checked my env variables, and even though PUPPETEER_SKIP_CHROMIUM_DOWNLOAD was set to false, it was still not working. After I removed the variable (unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD for mac), it worked.
related dependancies:
"dependencies": {
"chrome-aws-lambda": "^10.0.0",
"puppeteer-core": "^10.0.0",
},
"devDependencies": {
"puppeteer": "^10.0.0",
}
Launching Chromium:
import chromium from "chrome-aws-lambda";
const browser = await chromium.puppeteer.launch({
executablePath: await chromium.executablePath,
});
Upvotes: 10