Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase function Puppeteer Could not find Chromium GCP

I have been using GCP for a long time with google cloud, and I wanted to run a cloud function that uses Puppeteer, but unfortunately, I am getting the following error.


Unhandled error Error: Could not find Chromium (rev. 1069273). This can occur if either

  1. you did not install before running the script (e.g., npm install) or
  2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer). For (2), check out our guide on configuring Puppeteer at https://pptr.dev/guides/configuration. at ChromeLauncher.resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27) at ChromeLauncher.executablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:166:25) at ChromeLauncher.launch (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:70:37) at async /workspace/lib/index.js:122:21 at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26

My code is


export const test = functions
  .runWith({
    timeoutSeconds: 120,
    memory: "512MB" || "2GB",
  })
  .https.onCall(async (data, context) => {
    const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
    const page = await browser.newPage();
    await page.goto("https://www.google.com/");

    browser.close();
    return { msg: "all good", status: 200 };
  });

I copy from here an example of how to use Puppeteer in the GCP function (worked on my machine), I also tried other functions that don't use Puppeteer, which work fine (so I am sure the problem is with Puppeteer). I also tried to add the flag "--disable-setuid-sandbox" but that didn't work. I am writing the firebase function with Typescript. My package.json has the following settings.

"engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^10.2.0",
    "firebase-functions": "^3.21.0",
    "puppeteer": "^19.4.0"
  },
  "devDependencies": {
    "@types/puppeteer": "^7.0.4",
    "typescript": "^4.6.4"
  },
  "private": true

My tsconfig.json file has the following setting.

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "ES2020",
    "esModuleInterop": true,
    "rootDir": "src",
  },
  "compileOnSave": true,
  "include": [
    "src",
    "node_modules/@types/puppeteer/index.d.ts"
  ]
}

I also have in the lib directory the .puppeteerrc.cjs file according to here.

const {join} = require('path');

/**
 * @type {import("puppeteer").Configuration}
 */
module.exports = {
  // Changes the cache location for Puppeteer.
  cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

I tried adding it next to index.js, index.ts,package.json, firebase.json, but that did not change it. I tried deleting and reinstalling node_modules. I tried to follow StackOverflow questions. Deploying firebase function with Puppeteer says chrome can't be found even thoough I have enabled --no-sandbox

Not able to migrate firebase functions to node 10 runtime

puppeteer-in-firebase-functions-failed-to-launch-chrome

like image 213
shaked Avatar asked Dec 04 '25 00:12

shaked


1 Answers

downgrading puppeteer helped:

npm remove puppeteer
npm install [email protected] --save-dev
like image 134
Sebastian Viereck Avatar answered Dec 05 '25 17:12

Sebastian Viereck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!