Puppeteer failed to launch browser process

I am trying to use puppeteer in cron service, but I keep getting this error:

Jul 24 06:47:37 PM Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT
Jul 24 06:47:37 PM
Jul 24 06:47:37 PM
Jul 24 06:47:37 PM TROUBLESHOOTING: Troubleshooting | Puppeteer
Jul 24 06:47:37 PM
Jul 24 06:47:37 PM at ChildProcess.onClose (/opt/render/project/src/node_modules/@puppeteer/browsers/lib/cjs/launch.js:277:24)
Jul 24 06:47:37 PM at ChildProcess.emit (node:events:511:28)
Jul 24 06:47:37 PM at ChildProcess._handle.onexit (node:internal/child_process:291:12)
Jul 24 06:47:37 PM at onErrorNT (node:internal/child_process:483:16)
Jul 24 06:47:37 PM at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Below are the 3 things I’ve tried.

  1. Error could not found chromium - #8 by jeremy-render. so I have cron-build.sh that contains:
#!/usr/bin/env bash
# exit on errorset -o errexit
# source: https://community.render.com/t/error-could-not-found-chromium/9848/2
npm install
# npm run build # uncomment if required

# Store/pull Puppeteer cache with build cache
if [ ! -d $PUPPETEER_CACHE_DIR ] ; then 
  echo "...Copying Puppeteer Cache from Build Cache" 
  cp -R $XDG_CACHE_HOME/puppeteer/ $PUPPETEER_CACHE_DIR
else 
  echo "...Storing Puppeteer Cache in Build Cache" 
  cp -R $PUPPETEER_CACHE_DIR $XDG_CACHE_HOME
fi

Note, I use [ instead of [[ because [[ is compile error when I deployed, I am not familiar with bash so I hope this is correct.

  1. I also followed this post: Docker: puppeteer not working on a Express (NestJS) app - #4 by Jade_Paoletta so I have the following config passed to puppeteer:
{
  executablePath: '/usr/bin/chromium-browser',
  headless: 'new',
  slowMo: undefined
}
  1. I also created . puppeteerrc.cjs as suggested here Error could not found chromium - #9 by tomstove

NOTE:
When I ssh’ed into the service, I checked the suggested path /opt/render/project/puppeteer and when I listed the content, I did not see puppeteer, as show below.

==> Using Node version 20.3.0 via environment variable NODE_VERSION
==> Docs on specifying a Node version: Setting Your Node.js Version | Render Docs
render@towa-cron-shell:~/project/src$ ls /opt/render/project/
nodes src
render@towa-cron-shell:~/project/src$

Please advise on how to run puppeteer.

Hi there,

I think the issue here is that it was never cached because you added the build script to restore/copy Chrome to/from the cache after the first time the puppeteer module was installed.

Can you try building again with a clear cache? Unfortunately for cron jobs, we don’t have an easy way to do this, you will need to use our API: https://api-docs.render.com/reference/create-deploy, with clearCache set to clear.

You should only need the build script, nothing else.

I’d be also interested to know why it failed when using [[, it should work.

Regards,

Keith
Render Support, UTC+10 :australia:

Keith, it’s working now and to be honest since i tried so many things, I am not sure which one works for me. However, [[ still does not work, [ works however.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.