Enter the URL you'd like to take a screenshot of here
async
(params, auths) => {
}
// 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()
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
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!`)