For my main site I had to take screenshots of my webpages. I used puppetteer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import puppeteer from "puppeteer"; (async () => { // open the browser and prepare a page const browser = await puppeteer.launch({ headless: 'new', }); const page = await browser.newPage(); await page.setRequestInterception(true); const rejectRequestPattern = [ "googlesyndication.com", "/*.doubleclick.net", "/*.amazon-adsystem.com", "/*.adnxs.com", ]; const blockList = []; page.on("request", (request) => { if (rejectRequestPattern.find((pattern) => request.url().match(pattern))) { blockList.push(request.url()); request.abort(); } else request.continue(); }); // set the size of the viewport, so our screenshot will have the desired size await page.setViewport({ width: 1280, height: 800 }); await page.goto('https://c64g.com/') await page.screenshot({ path: 'images/c64g.com.png', fullPage: true }); await page.goto('https://xdslvergleich.de/') await page.screenshot({ path: 'images/xdslvergleich.de.png', fullPage: true }); // close the browser await browser.close(); }); |