Skip to content

Instantly share code, notes, and snippets.

@salman0ansari
Created March 25, 2023 08:30
Show Gist options
  • Save salman0ansari/fc7942685b1c690026b45705ae32b762 to your computer and use it in GitHub Desktop.
Save salman0ansari/fc7942685b1c690026b45705ae32b762 to your computer and use it in GitHub Desktop.
puppeteer serverless
import chromium from '@sparticuz/chrome-aws-lambda';
export const GenerateBuffer = async (content) => {
try {
const puppeteer = chromium.puppeteer;
const browser = await puppeteer.launch({
args: chromium.args,
executablePath: await chromium.executablePath,
});
console.log('We have a browser', browser);
const page = await browser.newPage();
await page.setContent(content);
console.log('We have a page', page);
const buffer = await page.screenshot({ path: 'default_image.png' });
console.log('We have a buffer', buffer);
await browser.close();
return buffer;
} catch (e) {
throw new Error(e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment