gen-screenshot: migrate to Playwright
This commit is contained in:
parent
414b049cd2
commit
ba7f521f5d
|
|
@ -1,9 +1,9 @@
|
||||||
#! /usr/bin/env -S deno run --allow-env --allow-net --allow-read --allow-run --allow-write --check
|
#! /usr/bin/env -S deno run --allow-env --allow-net --allow-sys --allow-read --allow-run --allow-write --check
|
||||||
// Generate the screenshot and its thumbnail for a project.
|
// Generate the screenshot and its thumbnail for a project.
|
||||||
// To install the dependencies on Debian/Ubuntu:
|
// To install the dependencies on Debian/Ubuntu:
|
||||||
// $ sudo apt install imagemagick optipng
|
// $ sudo apt install imagemagick optipng
|
||||||
|
|
||||||
import { launch } from "https://deno.land/x/astral@0.3.5/mod.ts";
|
import { chromium } from "npm:playwright";
|
||||||
|
|
||||||
const templateFile = "screenshot-page.html";
|
const templateFile = "screenshot-page.html";
|
||||||
const temporaryFile = "temp.html";
|
const temporaryFile = "temp.html";
|
||||||
|
|
@ -15,13 +15,12 @@ const slugify = (str: string) =>
|
||||||
.replace(/(^-|-$)/g, "");
|
.replace(/(^-|-$)/g, "");
|
||||||
|
|
||||||
const saveScreenshot = async (src: string, dest: string) => {
|
const saveScreenshot = async (src: string, dest: string) => {
|
||||||
const browser = await launch();
|
const browser = await chromium.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
const page = await browser.newPage(src);
|
|
||||||
await page.setViewportSize({ width: 1024, height: 1024 });
|
await page.setViewportSize({ width: 1024, height: 1024 });
|
||||||
|
await page.goto(src);
|
||||||
|
|
||||||
const screenshot = await page.screenshot({ captureBeyondViewport: true });
|
await page.screenshot({ path: dest, fullPage: true });
|
||||||
await Deno.writeFile(dest, screenshot);
|
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue