You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
How to Use Puppeteer With Firebase Cloud FunctionsEpisode 130 written by Jeff Delaney
Health Check: This lesson was last reviewed on and tested with these packages:
- CloudFunctions v
Find an issue? Let's fix it
Source code for How to Use Puppeteer With Firebase Cloud Functions on Github
Cloud Functions v2.0 provides support for Puppeteer, which means using headless chrome in a serverless environment is now possible. In the following lesson, you will learn how to setup Puppeteer in a Firebase Function and use it to perform serverside rendering of any site that lives on internet.
Potential use cases for headless chrome in Firebase include:
- Serverside Rendering and Prerendering
- Webcrawlers and Scrapers
- End-to-End and Performance Testing
Let’s make sure we have the latest version of the Firebase CLI Tools and initialize functions.
npm install [email protected] -g
Puppeteer requires Node8 or greater, so we need to setup that runtime in the
package.json in the functions directory.
Puppeteer is a web browser, hence it uses the DOM. By default, the
tsconfig.json for functions does not include the the DOM lib - let’s change that.
Puppeteer requires a good amount of memory. Let’s setup an HTTP function and give it a higher memory allocation by chaining
import * as functions from 'firebase-functions';
Notice how the
render function below has 1GB of memory on runs on Node8
This function is essentially a proxy browser that can be used by passing the desired url as a query parameter:
export const render = functions
And that’s all there is to it. You now have access to all the awesomeness of Puppeteer in a Firebase Cloud Function.