I'm working on a personal project which is an app where a user can input their address & credit card info and click a button to buy a parking permit for one of the universities that I visit often.
I want to host my front end in firebase's cloud storage and I want to create a cloud function where puppeteer code can run with the information that I save to the firebase's realtime database.
Is it possible for a firebase cloud function to run the puppeteer code that buys a parking permit?
Since puppeteer doesn't work with cloud functions, can I use Heroku to host the puppeteer code?
It's now possible to run Puppeteer inside Cloud Functions (as of August 13, 2018).
Note: some of these commands are in the "beta" SDK so will no doubt change in the future. The quick start guide contains the latest documentation.
1) At the time of writing, you need to use Node 8 and the beta components:
gcloud components update
gcloud components install beta
2) There's a "headless Chrome" example in the Node examples which shows how to create screenshot as a PNG (there are other options available though).
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
cd nodejs-docs-samples/functions/headless-chrome
3) Deploy the component
gcloud beta functions deploy screenshot --runtime nodejs8 --trigger-http
4) Finally, you'll need to increase the memory allocation. By default, Cloud Functions only get 256Mb of memory so you'll get an error if you try to run the Puppeteer without first changing the memory settings. Open your project in the Cloud Console, select Cloud Functions, select your function and click edit. 512Mb wasn't enough for me so I went up to 2Gb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With