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

3

6

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

Butterandeggs answered 16/2, 2023 at 13:40 Comment(0)
B
3

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"]
        });
Butterandeggs answered 24/2, 2023 at 3:41 Comment(1)
headless: true, → headless: false, it worked. thank you.Drayton
C
1

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"
  }
}
Chemise answered 16/3, 2023 at 13:59 Comment(0)
C
0

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.

Commercialize answered 27/2, 2023 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.