Troubleshooting Puppeteer on Firebase Functions: Chrome Not Found

Hey everyone, I’m running into a roadblock with my web scraper project. I’m using Puppeteer in Firebase Functions, but it’s not working as expected when deployed.

The error message I’m getting is:

Error: Could not find Chrome (ver. 134.0.6998.35).

It mentions something about installation or cache path issues. The weird thing is, it works fine on my local machine. I’m pretty new to this, so I’m probably missing something obvious.

Here’s the part of my code that’s likely causing trouble:

const browser = await puppeteer.launch({
  args: ['--no-sandbox', '--disable-gpu'],
  headless: 'new'
});

I’ve tried a few things, but I’m stumped. Any ideas on how to get this working on Firebase? Thanks for any help you can offer!

hey there! i ran into this too. try using puppeteer-core instead of regular puppeteer. also, install @sparticuz/chromium. then change ur code to use the chromium package for args and executablePath. that fixed it for me on firebase. good luck!

I’ve dealt with this issue before when deploying to Firebase Functions. The problem stems from the serverless environment not having Chrome installed by default. To resolve this, you’ll need to use a package that bundles Chromium specifically for serverless environments.

I recommend using ‘chrome-aws-lambda’ along with ‘puppeteer-core’. First, install both packages. Then, modify your code to use these instead:

const chromium = require(‘chrome-aws-lambda’);
const puppeteer = require(‘puppeteer-core’);

const browser = await puppeteer.launch({
args: chromium.args,
executablePath: await chromium.executablePath,
headless: chromium.headless
});

This approach should work smoothly on Firebase Functions. Remember to adjust your package.json and deployment settings accordingly. Let me know if you need any clarification on implementation details.

I encountered a similar issue when deploying Puppeteer on Firebase Functions. Firebase’s environment doesn’t include Chrome by default, so the usual Puppeteer package fails when trying to launch the browser. A good workaround is to switch from puppeteer to puppeteer-core and specify the Chrome executable path manually. You can install puppeteer-core and a compatible Chromium package, like @sparticuz/chromium, and then modify your code to import both. For example:

const puppeteer = require('puppeteer-core');
const chromium = require('@sparticuz/chromium');

const browser = await puppeteer.launch({
  args: chromium.args,
  defaultViewport: chromium.defaultViewport,
  executablePath: await chromium.executablePath(),
  headless: chromium.headless
});

This approach ensures that you use a version of Chrome that works with Firebase Functions. I hope this helps resolve your problem.