puppeteer: v3.0.0 does not work in google cloud funtions node10 runtime

Tell us about your environment:

  • Puppeteer version: 3.0.0
  • Platform / OS version: GCP functions
  • URLs (if applicable):
  • Node.js version: 10 (beta - in cloud functions)

I see that the latest release 3.0.0 does not support node8 anymore. So, I changed the runtime to 10 (beta) in my cloud functions and got this below error in the logs

Failed to launch the browser process! /workspace/node_modules/puppeteer/.local-chromium/linux-737027/chrome-linux/chrome: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory

I tried puppeteer v2.1.1 with node10 runtime and it worked.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 34
  • Comments: 42 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hi, I’m a PM on Google Cloud.

All OS packages available in Cloud Functions are listed on this page, libgbm1 is indeed not listed.

I will follow up with the Cloud Functions team to add it (internal bug number: 156270284)

I’d like to share a somehow-dirty-but-working fix, hoping it might help people like me that would like to try newer versions of Chromium on GCF (Google Cloud Functions) without waiting for the platform’s update.

It’s known from this page that the Node.js 8 & 10 environments on GCF use Ubuntu 18.04, on which the libgbm.so.1 binary is provided by package libgbm1.

By analyzing the package dependencies, examining the list of system packages of the Node.js environment on GCF, and some live inspection of the function execution environment, it’s known that there are (only) two additional packages that we need: libgbm1 and libwayland-server0.

Due to privilege limits we may not install system packages directly. However it’s okay to fetch the binaries at function deployment time (via npm’s pre/post script hooks) and explicitly ask the dynamic linker to use such binaries (via the LD_LIBRARY_PATH environment variable).

Please find below the proof-of-concept code that works for me (using the nodejs10 runtime):

$ cat package.json
{
  "name": "test",
  "main": "index.js",
  "dependencies": {
    "puppeteer": "3.1.0"
  },
  "scripts": {
    "postinstall": "for i in '1618226adb967b34670a06b6c9c28552717dfe0f434b9c6d7639144138948516 http://mirrors.kernel.org/ubuntu/pool/main/m/mesa/libgbm1_19.2.8-0ubuntu0~18.04.3_amd64.deb' '4f5cf9735170083aceb3d0c65ae64848102e9ef0aa0126effafcaf100f0f476c http://mirrors.kernel.org/ubuntu/pool/main/w/wayland/libwayland-server0_1.16.0-1ubuntu1.1~18.04.3_amd64.deb'; do wget ${i#* } && echo ${i% *} ${i##*/} | sha256sum -c && dpkg-deb -X ${i##*/} ./tmpdeb; done && cp ./tmpdeb/usr/lib/x86_64-linux-gnu/lib*.so* ./node_modules/puppeteer/.local-chromium/linux-*/chrome-linux/"
  }
}
$ cat index.js 
module.exports.render = async (req, res) => {
  const puppeteer = require('puppeteer');
  const browser = await puppeteer.launch({
    'env': {
      'LD_LIBRARY_PATH': puppeteer.executablePath().replace(/[^/]+$/, ''),
    },
    'dumpio': true,
  });
  const page = await browser.newPage();
  await page.goto('http://httpbin.org/get');
  res.status(200).send(await page.content());
  await page.close();
  await browser.close();
};

The checksum values above are obtained from the respective package pages: libgdm1 / libwayland-server0.

We are still pending the roll out of the change. It’s expected in 2 weeks.

in the meantime, you should be able to run v3.0.0 on Cloud Run, which allows you to bring a container that would have the missing OS package libgbm1.

expected in 2 weeks?

hi @ar-naseef,

Above puppeteer 3.0.0 you need to install libgbm1 as mentioned as solution in #5661

See in required Debian dependencies here: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix

(Docs were extended with v3.0.1)

sudo apt-get update
sudo apt-get install -y libgbm1

For me adding it in workflows it fixed the error in Github Actions (using Ubuntu latest).

Cheers

We are still pending the roll out of the change. It’s expected in 2 weeks.

in the meantime, you should be able to run v3.0.0 on Cloud Run, which allows you to bring a container that would have the missing OS package libgbm1.

@steren Do you have any progress or schedule to fix it?

I will follow up with the Cloud Functions team to add it (internal bug number: 156270284)

For those who wants to check on updates, it is happening here: https://issuetracker.google.com/issues/156772387

Same here puppeteer v3 fails to run on nodejs10 cloud function and fails with:

Function execution started
/workspace/node_modules/puppeteer/.local-chromium/linux-737027/chrome-linux/chrome: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory
Error: Failed to launch the browser process!

Which should not be the case based on Running Puppeteer on Google Cloud Functions Doc

cf

Version 2.1.1 works fine.

We are still pending the roll out of the change. It’s expected in 2 weeks.

in the meantime, you should be able to run v3.0.0 on Cloud Run, which allows you to bring a container that would have the missing OS package libgbm1.

Still not fixed? Seems cloud functions are more of a problem than a solution.

I fix it by downgrade to 2.1.1 lol then config with

const browser = await launch({ args: ['--no-sandbox' ] });

But I am not sure how we can install packages in cloud functions. Functions run in temporary instances.

If the features of puppeteer 3 are a must for you: check out Installing Google Cloud SDK, like this you will be able to apply the apt-get install even on temporary instances.

I updated puppeteer to the latest version(“puppeteer”: “^5.4.1” / “@types/puppeteer”: “^3.0.4”) and confirmed it works in cloud functions.

Ran into the same issue, and got it working by upgrading to nodejs12

This is not possible for firebase users (which runs on google cloud).

Sure thing.

But I am not sure how we can install packages in cloud functions. Functions run in temporary instances.

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

If anyone is trying to make it work on Cloud Function with Node 14, I had to use the following to make it work:

const browser = await puppeteer.launch({
    headless: true,
    slowMo: 75, // slow down by 250ms
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '--disable-dev-shm-usage',
      '--no-first-run',
      '--no-zygote',
      '--headless',
      '--disable-gpu',
    ],
  });

without the args the browser was never launched, and the function timed out. I’m not sure which one are the absolutely necessary to make it work.

After poking around some more, I figured out that it was this line

await page.setJavaScriptEnabled(true);

that is causing it to hang.

I tried too and i confirm, it doesn’t work with version 12 ! Thanks

Leaving a comment because this messed me up for a night and maybe it’ll help someone: If you are going to downgrade when using firebase functions remember to run npm install in your functions folder. They do not run it on the cloud side - you upload your dependencies with your function. So you can change it to say “puppeteer”:“2.1.1” but it won’t work until after you run npm install. Downgrading worked just fine for me after I ran npm install but I spent a whole night trying to figure that out.

Sir can you please share the repository or code snippet where you are starting the browser

sure man:

    let browser: Browser
    try {
      browser = await launch({
        headless: true,
        pipe: true,
        args: [
          '--no-sandbox',
          '--disable-setuid-sandbox',
          '--disable-dev-shm-usage',
          '--no-first-run',
          '--no-zygote',
          '--headless',
          '--disable-gpu',
          '--use-fake-ui-for-media-stream',
          '--use-fake-device-for-media-stream',
          '--use-file-for-fake-audio-capture=../functions/fakeAudio.mp3',
          '--allow-file-access'
        ]
      })
    } catch (e) {
      console.log('Error launching browser ' + e.message)
      browser = await launch({
        headless: true,
        pipe: true,
        args: [
          '--no-sandbox',
          '--disable-setuid-sandbox',
          '--disable-dev-shm-usage',
          '--no-first-run',
          '--no-zygote',
          '--headless',
          '--disable-gpu',
          '--use-fake-ui-for-media-stream',
          '--use-fake-device-for-media-stream',
          '--use-file-for-fake-audio-capture=../functions/fakeAudio.mp3',
          '--allow-file-access'
        ]
      })
    }

Leaving a comment because this messed me up for a night and maybe it’ll help someone:

If you are going to downgrade when using firebase functions remember to run npm install in your functions folder. They do not run it on the cloud side - you upload your dependencies with your function. So you can change it to say “puppeteer”:“2.1.1” but it won’t work until after you run npm install. Downgrading worked just fine for me after I ran npm install but I spent a whole night trying to figure that out.

Looks promising