4

I am trying to build a solution with Selenium, can I use Firebase Functions to initialize and load webpages with Selenium?

I have found some resources that state no; however they don't give any source and they are 4 years old..:

How or where can I check if this is still the case?

Gourav B
  • 864
  • 5
  • 17
Peter Toth
  • 678
  • 6
  • 23

3 Answers3

5

You can't currently use Python to run Selenium scripts in Google Cloud Functions. There's a Feature Request in the Public Issue Tracker currently open, that can be found here. For the Node.js runtime for your Cloud Functions, you could use puppeteer which includes headless Chrome. I found this blog post that details a use-case.

Or if you are ready to trade Python for Cloud functions, we have other services like : App Engine Flex and Cloud Run where you can get it working in Python.

I also found this GitHub link which vouches to run selenium on Google Cloud Functions. If you're fine with a JavaScript/TypeScript example instead of Python, I recommend that you try this template. However, I have not tested this.

Priyashree Bhadra
  • 3,182
  • 6
  • 23
0

TLDR: No you can't open any sort of webpage (that is not just an API call) with firebase functions.

You can use Google Cloud Run to have selenium / cypress / spyder run. GCR achieves a similaresq result, that being it is serverless and scalable.

Peter Toth
  • 678
  • 6
  • 23
0

Yes you can use Selenium WebDriver with Google Cloud Functions in nodejs.

You will need an additional library chromium (https://github.com/dtolstyi/node-chromium). It will download chromium binary inside the node-modules. This is needed as chrome is not installed in cloud functions. You can refer the below code how to create the driver instance using the brinary.

  const chromium = require('chromium');

export function createDriver() {

  const chromeOptions = new Options();
  chromeOptions.setChromeBinaryPath(chromium.path);
  chromeOptions.addArguments('--no-sandbox');
  chromeOptions.addArguments('--disable-dev-shm-usage'); // overcome limited resource problems
  if (headless) {
    chromeOptions.addArguments('headless');
  }

  const driver = new Builder()
    .forBrowser('chrome')
    .setChromeOptions(chromeOptions)
    .build();

  return driver;
}

If you want to download a specific chromium version then you need to add below config in the .npmrc file.

node_chromium_revision = 1002548

You need to specify the chromium revision here. Chromium revisions can be found from here (https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Linux_x64/).

Akshoy
  • 177
  • 1
  • 4