Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using puppeteer-core and chrome-aws-lamba to screenshot a web element
// Code from
// and
// and thanks wes.bos for the video on this at
const chrome = require("chrome-aws-lambda");
const puppeteer = require("puppeteer-core");
const exePath = "/usr/bin/google-chrome";
async function getOptions(isDev) {
let options;
if (isDev) {
options = {
args: ["--incognito"],
executablePath: exePath,
headless: true,
} else {
options = {
args: chrome.args,
executablePath: await chrome.executablePath,
headless: chrome.headless,
return options;
async function getScreenshot(url, isDev) {
const options = await getOptions(isDev);
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
await page.setViewport({ width: 720, height: 1920, deviceScaleFactor: 1.5 });
await page.goto(url);
return await page.screenshot({ type: "jpeg", quality: 100 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment