I have developed a nodeJS based project using puppeteer and lighthouse. I am using puppeteer to login to any of the websites where user needs to login. After login, i navigate to any pages like my order, account info, ordered page, etc.
Note- I have this as a free style project on jenkins.
Exact Error in Details-
Exception encountered: Could not find Chromium (rev. 1095492). This can occur if either
- you did not perform an installation before running the script (e.g.
npm install
) or - your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
Tried below 3 scripts to run before calling my script–>
-
apt-get update
-
apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
-
npm install -g
npm run MyScriptName
Package.json–>
"devDependencies": {
"chromedriver": "^108.0.0",
"date-and-time": "^2.4.1",
"lighthouse": "^9.6.8",
"log4js": "^6.7.1",
"puppeteer": "^19.7.1"
},
3
Answers
I was able to resolve this using the code below:
Now chrome is placed in the user directory
"~/.cache/puppeteer"
. Check the permissions of the directory and that it belongs to the user you are running the application as.Or set Chromium download folder via
PUPPETEER_CACHE_DIR
environment variable or apuppeteer.config.cjs
config file.index.js
package.json
it worked with Google Cloud Functions Node.js 16
https://issuetracker.google.com/issues/266279679?pli=1
ES Modules
index.mjs
package.json