Search code examples
jenkinspuppeteerchromiumdebian-based

Exception encountered: Could not find Chromium (rev. 1095492) when running puppeteer script in Jenkins (Has Debian as machine)


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

  1. you did not perform an installation before running the script (e.g. npm install) or
  2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).

Tried below 3 scripts to run before calling my script-->

  1. apt-get update

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

  3. 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" },


Solution

  • I was able to resolve this using the code below:

    const browserFetcher = puppeteer.createBrowserFetcher();
          let revisionInfo = await browserFetcher.download('1095492');
    
          const browser =await puppeteer.launch({
              executablePath: revisionInfo.executablePath,
              ignoreDefaultArgs: ['--disable-extensions'],
              headless: true,
              args: ['--no-sandbox', "--disabled-setupid-sandbox"]
            });