Fix Puppeteer Chrome Error in Firebase Functions
In this article
When you deploy a Cloud Function that uses Puppeteer, you often hit the Could not find Chrome error. This happens because Firebase Functions run in a stripped-down Node.js environment that lacks a system Chrome installation. The fix is to install a compatible Chromium build inside your function's dependencies and tell Puppeteer to use it. This guide walks you through the exact steps to make Puppeteer work reliably on Firebase Functions (both gen 1 and gen 2).
What You'll Need
- A Firebase project with Cloud Functions enabled (Blaze plan, since outbound network is required).
- Firebase CLI installed and logged in (
firebase login). - Node.js 18 or 20 locally (matching your function runtime).
- Basic familiarity with the command line and your
functions/folder.
Step-by-Step
- Navigate to your functions folder:
cd functionsin your terminal. - Remove any existing Puppeteer installation to avoid version conflicts:
npm uninstall puppeteer. - Install Puppeteer with its Chromium download skipped:
npm install puppeteer-core. This package does not download a browser by default, which is what you want. - Install a compatible Chromium build that runs on Cloud Functions. The most reliable option is
chrome-aws-lambda(even though it's named for Lambda, it works on Firebase):npm install chrome-aws-lambda. - Set the Puppeteer executable path in your function code. At the top of your function file, add:
const chromium = require('chrome-aws-lambda'); const puppeteer = require('puppeteer-core'); exports.myFunction = functions.https.onRequest(async (req, res) => { let browser; try { browser = await puppeteer.launch({ args: chromium.args, executablePath: await chromium.executablePath, headless: chromium.headless, }); // ... your scraping logic ... } finally { if (browser) await browser.close(); } }); - Increase the function's memory and timeout in
functions/index.jsor your deployment config. For example:
This prevents out-of-memory crashes and gives Chrome time to boot.exports.myFunction = functions.runWith({ memory: '1GB', timeoutSeconds: 120 }).https.onRequest(...) - Deploy:
firebase deploy --only functions. - Test your function by hitting its URL. If it still fails, check the logs (see Troubleshooting).
Common Mistakes
- Using the regular
puppeteerpackage instead ofpuppeteer-core. The regular package tries to download Chrome during install, which often fails or gets removed in the cloud environment. - Not setting
executablePath. Without it, Puppeteer looks for Chrome in default system paths that don't exist on Cloud Functions. - Using
chrome-aws-lambdawith an incompatible Node version. The package supports Node 12+ but always test with your runtime. - Forgetting to close the browser. This causes memory leaks and can crash subsequent invocations.
- Setting memory too low (e.g., 256MB). Chrome needs at least 512MB to run comfortably.
Tips
- Use
puppeteer-coreandchrome-aws-lambdaversions that are known to work together. As of this writing,puppeteer-core@^21andchrome-aws-lambda@^10are a safe combo. - If you only need to take a screenshot or scrape a simple page, consider using
@sparticuz/chromiumas an alternative tochrome-aws-lambda. It's actively maintained and works on Firebase. - Set
NODE_ENV=productionin your function's environment variables to reduce debug overhead. - Add a fallback: if
chromium.executablePathreturns null (e.g., in local emulation), use a locally installed Chrome path. - Use
functions.config()to store the executable path if you ever need to change it without redeploying.
Troubleshooting
If the error persists, follow these checks in order:
- Check the logs: Run
firebase functions:logto see the exact error message. It often saysspawn ... ENOENTorCould not find Chrome. - Verify the executable path: Add a log line
console.log(await chromium.executablePath)and deploy. If it logsnull, the Chromium binary wasn't installed. Re-runnpm installand redeploy. - Check dependencies: Make sure
chrome-aws-lambdais in yourpackage.jsondependencies, not devDependencies. Firebase only installs production dependencies. - Test locally: Run your function with
firebase emulators:startto see if it works locally. If it does, the issue is likely environment-specific. - Try a different Chromium package: If
chrome-aws-lambdafails, switch to@sparticuz/chromiumand adjust the launch code:const chromium = require('@sparticuz/chromium'); const puppeteer = require('puppeteer-core'); browser = await puppeteer.launch({ args: chromium.args, executablePath: await chromium.executablePath(), headless: chromium.headless, }); - Check region: Some regions might have stricter network policies. Try deploying to
us-central1(default) if you used another.
Frequently Asked Questions
Why does Puppeteer work locally but not on Firebase Functions?
Locally, Puppeteer finds your system Chrome. On Firebase Functions, there is no Chrome installed, and the default Puppeteer package can't download one during deployment.
Can I just use the regular puppeteer package with a custom executable path?
You can, but it's not recommended because the regular package downloads a large Chromium binary during install, which may be stripped or cause deployment timeouts. Using puppeteer-core avoids that.
What is the difference between chrome-aws-lambda and @sparticuz/chromium?
Both provide a pre-built Chromium binary for serverless environments. chrome-aws-lambda is older but widely used; @sparticuz/chromium is a community fork that is more actively maintained and often has newer Chromium versions.
Do I need to set the CHROME_PATH environment variable?
No, because you're setting executablePath in the Puppeteer launch options. That overrides any default path.
Will this work on Firebase gen 2 (Cloud Run) functions?
Yes, the same approach works on both gen 1 and gen 2. Gen 2 may have slightly different resource limits, but the Chromium installation method is identical.
How do I reduce the cold start time?
Use a memory setting of 1GB or higher, and consider keeping the browser instance alive across invocations if your function is called frequently. But be careful with connection limits; it's often safer to launch per request.