skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    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"]
            });
    

  2. 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 a puppeteer.config.cjs config file.

    Login or Signup to reply.
  3. index.js

    const puppeteer = require('puppeteer')
    
    /**
     * Responds to any HTTP request.
     *
     * @param {!express:Request} req HTTP request context.
     * @param {!express:Response} res HTTP response context.
     */
    exports.helloWorld = async (req, res) => {
      await puppeteer.createBrowserFetcher().download(puppeteer.PUPPETEER_REVISIONS.chromium)
      const browser = await puppeteer.launch()
      const page = await browser.newPage()
      await page.goto('https://example.com/')
      res.send(await page.content())
      await browser.close()
    }
    

    package.json

    {
      "name": "sample-http",
      "version": "0.0.1",
      "dependencies": {
        "puppeteer": "^19.7.5"
      }
    }
    

    it worked with Google Cloud Functions Node.js 16

    https://issuetracker.google.com/issues/266279679?pli=1

    ES Modules

    index.mjs

    import puppeteer from 'puppeteer'
    
    /**
     * Responds to any HTTP request.
     *
     * @param {!express:Request} req HTTP request context.
     * @param {!express:Response} res HTTP response context.
     */
    export const helloWorld = async (req, res) => {
      await puppeteer.createBrowserFetcher().download(puppeteer.defaultBrowserRevision)
      const browser = await puppeteer.launch()
      const page = await browser.newPage()
      await page.goto('https://example.com/')
      res.send(await page.content())
      await browser.close()
    }
    

    package.json

    {
      "name": "sample-http",
      "main": "index.mjs",
      "version": "0.0.1",
      "dependencies": {
        "puppeteer": "^19.7.5"
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search