Created
January 16, 2019 05:52
-
-
Save hashaam/357ad0460dee25b3e729e3aa0f622ed8 to your computer and use it in GitHub Desktop.
This firebase cloud function takes screenshot of google home page and saves in firebase storage bucket under screenshots/google.png, every time it is run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from 'firebase-functions'; | |
import * as admin from "firebase-admin"; | |
import * as puppeteer from "puppeteer"; | |
admin.initializeApp() | |
export const takeGoogleScreenshot = functions | |
.runWith({ memory: "1GB" }) | |
.https.onRequest(async (request, response) => { | |
const browser = await puppeteer.launch({ | |
args: ["--no-sandbox", "--disable-setuid-sandbox"] | |
}) | |
const page = await browser.newPage() | |
await page.goto("https://www.google.com", {waitUntil: 'networkidle2'}) | |
const bucket = admin.storage().bucket("screenshots") | |
const file = bucket.file("google.png") | |
const screenshotBuffer = await page.screenshot({ fullPage: true }) | |
await file.save(screenshotBuffer) | |
await browser.close() | |
response.send("done") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just what I needed for my app thank you. I have modified it to run on a firestore cloud function trigger but I am hitting an error in the logs when the cloud function executes:
Adding chromuim in the dependencies doesn't fix it unfortunately