From 19af51fcd4f961d9af8d0ae962d592316ffe1b5a Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Tue, 28 May 2024 15:29:27 +0000 Subject: [PATCH] gen-screenshot: replace deno-puppeteer with Astral deno-puppeteer has not been updated since 2022, and I am having trouble running it. --- gen-screenshot.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gen-screenshot.ts b/gen-screenshot.ts index 95c367f..081021b 100755 --- a/gen-screenshot.ts +++ b/gen-screenshot.ts @@ -3,7 +3,7 @@ // To install the dependencies on Debian/Ubuntu: // $ sudo apt install imagemagick optipng -import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts"; +import { launch } from "https://deno.land/x/astral@0.3.5/mod.ts"; const templateFile = "screenshot-page.html"; const temporaryFile = "temp.html"; @@ -15,13 +15,13 @@ const slugify = (str: string) => .replace(/(^-|-$)/g, ""); const saveScreenshot = async (src: string, dest: string) => { - const browser = await puppeteer.launch({ - defaultViewport: { width: 1024, height: 1024, deviceScaleFactor: 1 }, - }); - const page = await browser.newPage(); + const browser = await launch(); - await page.goto(src); - await page.screenshot({ fullPage: true, path: dest }); + const page = await browser.newPage(src); + await page.setViewportSize({ width: 1024, height: 1024 }); + + const screenshot = await page.screenshot({ captureBeyondViewport: true }); + await Deno.writeFile(dest, screenshot); await browser.close(); };