Serverless-chrome: Support for Google Cloud Functions

Created on 15 Jul 2017  Â·  16Comments  Â·  Source: adieuadieu/serverless-chrome

Add support for Google Cloud Functions with package @serverless-chrome/cloud-functions and appropriate headless chrome binaries, and include Dockerfile for building Chrome binary. Not super sure about the package name:

@serverless-chrome/lambda
@serverless-chrome/cloud-functions
@serverless-chrome/az-functions

.. a bit inconsistent.

Related: #44 — Support for Azure Functions

enhancement

Most helpful comment

@adieuadieu I'm starting on this and ready to contribute. Do you have a branch published?

All 16 comments

Someone tried to run chrome on GCF? I've tried to use the binary included with the repo and chrome silently exits with exit code 127, no other stdout/err

Update: after some digging there are some .so files missing, I've tried to run chrome binary on ubuntu docker image and from there I've copied these libraries:

|-- libnspr4.so
|-- libnss3.so
|-- libnssutil3.so
|-- libosmesa.so
|-- libplc4.so
|-- libplds4.so
|-- libsmime3.so
|-- libssl3.so
`-- nss
    |-- libfreebl3.chk
    |-- libfreebl3.so
    |-- libnssckbi.so
    |-- libnssdbm3.chk
    |-- libnssdbm3.so
    |-- libnsssysinit.so
    |-- libsoftokn3.chk
    `-- libsoftokn3.so

This makes chrome at least start.
The problem is, due the fact the only writable folder on GCF is /tmp I had to move chrome there along with the above libraries and set LD_LIBRARY_PATH accordingly, this makes libnss3 search for the nssdb in /tmp/.pki/nssdb.
I've tried to copy the contents of /var/lib/nssdb there but chrome still crashes with:

[0729/072216.817840:WARNING:resource_bundle.cc(338)] locale_file_path.empty() for locale
[0729/072216.822776:WARNING:resource_bundle.cc(338)] locale_file_path.empty() for locale
[0729/072216.825442:VERBOSE1:zygote_main_linux.cc(626)] ZygoteMain: initializing 0 fork delegates
[0729/072216.825727:INFO:cpu_info.cc(50)] Available number of cores: 1
[0729/072216.835971:ERROR:devtools_http_handler.cc(759)] Error writing DevTools active port to file
[0729/072216.836504:VERBOSE1:webrtc_internals.cc(106)] Could not get the download directory.
[0729/072216.841256:VERBOSE1:proxy_service.cc(958)] PAC support disabled because there is no system implementation
[0729/072216.844030:ERROR:nss_util.cc(706)] Error initializing NSS with a persistent database (sql:/tmp/.pki/nssdb): NSS error code: -8023
[0729/072216.844228:VERBOSE1:nss_util.cc(712)] Initializing NSS without a persistent database.
[0729/072216.844354:ERROR:nss_util.cc(201)] Error initializing NSS without a persistent database: NSS error code: -8023
[0729/072216.856111:WARNING:histograms.cc(40)] Started multiple compositor clients (Browser, Renderer) in one process. Some metrics will be disabled.
[0729/072216.844795:FATAL:nss_util.cc(203)] nss_error=-8023, os_error=0
...very long stacktrace...

If someone is able to make some progress please ping me since I'll have to make this work somehow :D

Hi @alex88 the Lambda binary isn't compiled with the GCF execution environment in mind. However, I have been working on making a GCF-specific build. If nothing unexpected comes up, I should have it working sometime this coming week. :smile:

Thank you @adieuadieu, you know the OS/environment GCF runs on?

@adieuadieu, eager to know if you were able to get the GCF-specific build working.

@adieuadieu I'm starting on this and ready to contribute. Do you have a branch published?

Hej, we'd love to use a GCF implementation. Any progress here? What are the current blockers?

Note that the Node.js 8 runtime for Google Cloud Functions now includes all the necessary OS packages to run Headless Chrome.

Here is a code sample of an HTTP function that returns screenshots:

Main index.js file:

const puppeteer = require('puppeteer');

exports.screenshot = async (req, res) => {
  const url = req.query.url;

  if (!url) {
    return res.send('Please provide URL as GET parameter, for example: <a href="?url=https://example.com">?url=https://example.com</a>');
  }

  const browser = await puppeteer.launch({
    args: ['--no-sandbox']
  });
  const page = await browser.newPage();
  await page.goto(url);
  const imageBuffer = await page.screenshot();
  browser.close();

  res.set('Content-Type', 'image/png');
  res.send(imageBuffer);
}

and package.json

{
  "name": "screenshot",
  "version": "0.0.1",
  "dependencies": {
    "puppeteer": "^1.2.0"
  }
}

@steren nice! Then there's no need for us to do anything! 🎉

what about Java ? I'm using Selenium Java and would like to use GCP instead of AWS.

what about Java ? I'm using Selenium Java and would like to use GCP instead of AWS.

afair gcp functions support only js and python

@steren It seems some of those libraries (libssl3) where just dropped from the Node 8 runtime. Any idea why?

The base image has changed between the Node6 and Node8 runtimes.
As I commented, the Node8 runtime has all libraries needed to run headless chrome.

Sorry @steren, this is probably not the most appropriate place to discuss this.

I'm not exactly using this package (serverless-chrome), nor puppeteer mentioned in this GCP blog.

But I am using something else (aws-lambda-libreoffice) that depended on much the same libs.

Something changed between 12 and 2pm GMT today. libssl3.so is now missing from every function I've redeployed since 3pm. This a beta and I really can't complain, but I'd still like to know what happened, can I reach the team somewhere more appropriate?

I'm in the process of testing puppeteer directly to see if it's similarly affected.

Let's move this discussion to the Cloud Function issue tracker. Please open an issue there and ping it to me.

@steren, thanks: https://issuetracker.google.com/issues/118423830

And sorry adieuadieu for hijacking this issue.

Closing this as GCP has built-in package support for Chrome. Nothing for us to do.

Was this page helpful?
0 / 5 - 0 ratings