After following a discussion at the GatsbyJS discord space about running puppeter using a cloud function. I decided to give it a try and in this post I will share my experience.
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default.
This library comes with everything you need to:
For te purpose of tihs example we are going to take advantage of the screenshot generation.
For the purpose of this example. I will be using a Cloud Function from Google Firebase service
To use Puppeteer in your project using execute on your functions directory:
The following example creates a new function to handle the request using the url. This returns a screenshot of the provided query parameter.
Note the method is used in order to set timeout and memory allocation used on the cloud function execution.