Troubleshooting Puppeteer issues in Firebase Cloud Functions

Hey everyone, I’m having a tough time with my Firebase cloud function. I’m trying to use puppeteer-extra, but it’s not working as expected. When the function runs, I get an error saying Puppeteer is missing. It’s weird because I’ve already installed it.

Here’s what I’ve got in my package.json:

{
  "dependencies": {
    "puppeteer": "^5.4.1",
    "puppeteer-extra": "^3.1.15",
    "puppeteer-extra-plugin-stealth": "^2.6.3"
  }
}

And here’s how I’m setting it up in my code:

const puppeteerExtra = require('puppeteer-extra');
const stealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteerExtra.use(stealthPlugin());

exports.myCloudFunction = functions.https.onCall((data, context) => {
  async function doStuff() {
    try {
      const browser = await puppeteerExtra.launch({ headless: false });
      // More code here
    } catch(error) {
      // Error handling
    }
  }
});

I tried switching to regular puppeteer, but then I couldn’t deploy the function at all. Any ideas what’s going on? Thanks!

yo, have u tried using puppeteer-core instead? it’s a lighter version that might work better in cloud functions. also, make sure ur using headless mode (headless: true) and add some extra args like ‘–no-sandbox’ and ‘–disable-setuid-sandbox’. if that don’t work, try bumping up the memory allocation for ur function. sometimes puppeteer needs more juice to run smooth

Hey there! I’ve been down this Puppeteer rabbit hole with Firebase functions before, and it can be a real pain. Have you tried tweaking your launch options? I found success by switching to headless mode and adding some extra args. Here’s what worked for me:

const browser = await puppeteerExtra.launch({
  headless: true,
  args: ['--no-sandbox', '--disable-setuid-sandbox']
});

Also, make sure your function has enough memory. Puppeteer can be a resource hog. I had to bump up my function’s memory allocation in the Firebase config.

If you’re still hitting walls, consider using puppeteer-core instead of the full package. It’s more lightweight and might play nicer with Cloud Functions.

Lastly, double-check your Node.js version in the Cloud Functions environment. Sometimes version mismatches can cause weird issues with Puppeteer. Hope this helps! Let me know if you need more details.

Have you considered using a headless Chrome browser in your Firebase function? I ran into similar issues and found that switching to headless mode solved the problem. Change your launch options to { headless: true, args: ['--no-sandbox'] }. Also, make sure you’re using a compatible version of Puppeteer with your Node.js version in the Cloud Functions environment. If you’re still facing issues, try explicitly installing Chrome in your function’s setup. You can do this by adding a shell script to install Chrome during deployment. Lastly, check your function’s memory allocation - Puppeteer can be resource-intensive, so you might need to increase the allocated memory in your Firebase config.