Hey everyone, I’m having a tough time getting Puppeteer to work on Google App Engine’s standard environment for PDF generation. I’ve tried a bunch of different setups and read through the docs, but no luck so far.
Here’s what I’ve got:
- A
.puppeteerrc.cjs.js
file in the root folder with some config stuff.
- A
.puppeteer_cache
folder in node_modules
.
- An updated
package.json
that lists Puppeteer as a dependency and includes various scripts.
- A function specifically built to create PDFs using Puppeteer.
However, when I run the code, I encounter this error:
Error: Could not find Chrome (ver. 131.0.6778.204). This can occur if either 1. you did not perform an installation before running the script (e.g. npx puppeteer browsers install chrome) or 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).
I’m at a loss here. Has anyone experienced this or have any suggestions on what might be going wrong? Thanks for any help!
hey tom, have u tried using the headless chrome buildpack? it’s a lifesaver for puppeteer on gae. just add this to ur app.yaml:
buildpacks:
then update ur code to use the chrome executable path:
const browser = await puppeteer.launch({
executablePath: ‘/usr/bin/google-chrome’
});
hope this helps!
I’ve faced similar issues with Puppeteer on Google App Engine before. One thing that worked for me was explicitly setting the executable path for Chrome in my Puppeteer configuration.
Try adding this to your Puppeteer launch options:
const browser = await puppeteer.launch({
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
Also, make sure you’re including the necessary buildpacks in your app.yaml
file:
runtime: nodejs
env: flex
env_variables:
NODE_ENV: 'production'
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 2
disk_size_gb: 10
buildpacks:
- gcr.io/gcp-runtimes/nodejs
- gcr.io/googlepuppeteer/chrome-headless
This setup should help Puppeteer find and use the correct Chrome executable on GAE. Let me know if you still run into issues!
Have you considered using a custom runtime environment instead of the standard one? I’ve had success with Puppeteer on GAE by switching to a flexible environment and using a custom Dockerfile. This approach gives you more control over the runtime and allows you to install Chrome directly.
In your Dockerfile, you can include commands to install Chrome and its dependencies. Then, in your app code, use the --no-sandbox flag when launching Puppeteer. This bypasses some of the security restrictions that might be causing issues.
Also, double-check your .gcloudignore file to ensure it’s not excluding any necessary files or folders. Sometimes, crucial components get left out during deployment, leading to these kinds of errors.
If you’re still stuck, consider using Cloud Run instead. It offers more flexibility for running containerized apps and might be a better fit for your Puppeteer-based PDF generation service.