
Take Website Screenshots with Code: One API Call, No Puppeteer Setup
Taking screenshots of websites programmatically is one of those tasks that sounds simple until you actually try it. You need Puppeteer or Playwright, a headless Chromium binary, proper error handling for timeouts and navigation failures, and a server with enough memory to run a browser. Or... you can make one API call. The Hard Way (Puppeteer) // First: npm install puppeteer (downloads 300MB+ Chromium) const puppeteer = require ( ' puppeteer ' ); async function screenshot ( url ) { const browser = await puppeteer . launch ({ headless : ' new ' , args : [ ' --no-sandbox ' , ' --disable-setuid-sandbox ' ] }); const page = await browser . newPage (); await page . setViewport ({ width : 1280 , height : 720 }); await page . goto ( url , { waitUntil : ' networkidle2 ' , timeout : 30000 }); const buffer = await page . screenshot ({ type : ' png ' }); await browser . close (); return buffer ; } This works locally, but deploying it is painful. Chromium needs 400MB+ of disk, ~500MB RAM per insta
Continue reading on Dev.to Tutorial
Opens in a new tab




