Created
March 25, 2023 08:30
-
-
Save salman0ansari/fc7942685b1c690026b45705ae32b762 to your computer and use it in GitHub Desktop.
puppeteer serverless
This file contains 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 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