Take a screenshot with Browserless, save to S3
@dylburger
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
take_screenshot
auth
(auths.browserless)
params
URL

Enter the URL you'd like to take a screenshot of here

 
https://example.com
string ·params.url
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
}
21
// See the browserless docs for more info:
// https://docs.browserless.io/
const puppeteer = require('puppeteer-core') 

const browser = await puppeteer.connect({ 
  browserWSEndpoint: `wss://chrome.browserless.io?token=${auths.browserless.api_key}` 
})
const page = await browser.newPage()

await page.goto(params.url)
const screenshot = await page.screenshot()

// export the base64-encoded screenshot for use in future steps,
// along with the image type and URL
this.screenshot = Buffer.from(screenshot, 'binary').toString('base64')
this.type = "png"
this.url = params.url

await browser.close()
steps.
save_to_s3
auth
to use OAuth tokens and API keys in code via theauths object
(auths.aws)
params
Bucket
 
string ·params.bucket
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
}
23
const AWS = require("aws-sdk")

const { bucket } = params
const { url, screenshot, type } = steps.take_screenshot
const { accessKeyId, secretAccessKey } = auths.aws

const s3 = new AWS.S3({
  accessKeyId, 
  secretAccessKey,
})

// Store screenshot at object tied to site + current epoch
const Key = `${url.replace(/[&\/\\#, +()$~%.'":*?<>{}]/g, '_')}-${+new Date()}.${type}`
const uploadParams = { 
  Bucket: bucket, 
  Key, 
  Body: Buffer.from(screenshot, 'base64'),
  ContentType: `image/${type}`
}
this.S3Response = await s3.upload(uploadParams).promise()
console.log(`Uploaded file to S3!`)