Skip to content

Commit d68b5ec

Browse files
refactor: replace puppeteer with astral for screenshot and close #2919 (#2920)
due to resolves the `NotFound: No such file or directory` error in the `www/utils/screenshot.ts` script, which was caused by improper file path construction. This error prevented screenshots from being saved correctly. close #2919 -- update --patch1 ## Current Status - Using npm:puppeteer for webpage screenshots - npm lifecycle script warnings present - deno-puppeteer is no longer maintained - npm:puppeteer still has compatibility issues ## References - [astral](https://github.com/lino-levan/astral): Browser automation library designed for Deno - [deno-puppeteer#92](lucacasonato/deno-puppeteer#92): Recent discussion about deno-puppeteer ## Changes Made 1. Dependency Replacement - Replaced npm:puppeteer with jsr:@astral/astral - Removed npm lifecycle script warnings 2. Dependency Management Optimization - Centralized all imports in deno.json - Using jsr: and URL imports ## Testing Steps 1. Run screenshot command: ```bash deno task screenshot https://google.com google ``` 2. Check output: - Verify no npm warnings - Validate generated image files: - ./www/static/showcase/google2x.jpg - ./www/static/showcase/google1x.jpg - Confirm image quality 3. Run complete test suite: ```bash deno task ok ``` - Ensure all tests pass 4. Verify functionality: - Screenshot feature works correctly - Image processing (2x/1x) functions properly --------- Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com> Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
1 parent 09705b9 commit d68b5ec

File tree

3 files changed

+42
-111
lines changed

3 files changed

+42
-111
lines changed

deno.lock

Lines changed: 26 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@std/path": "jsr:@std/path@1",
2222
"@std/semver": "jsr:@std/semver@1",
2323
"@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",
24+
"astral": "jsr:@astral/astral",
2425
"autoprefixer": "npm:autoprefixer@10.4.17",
2526
"cssnano": "npm:cssnano@6.0.3",
2627
"esbuild": "npm:esbuild@0.23.1",
@@ -30,6 +31,7 @@
3031
"fresh/dev": "../src/dev/mod.ts",
3132
"fresh/runtime": "../src/runtime/shared.ts",
3233
"github-slugger": "npm:github-slugger@^2.0.0",
34+
"imagescript": "https://deno.land/x/imagescript@1.3.0/mod.ts",
3335
"marked": "npm:marked@^14.1.2",
3436
"marked-mangle": "npm:marked-mangle@^1.1.9",
3537
"postcss": "npm:postcss@8.4.35",

www/utils/screenshot.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import puppeteer from "npm:puppeteer@24.7.2";
2-
import { Image } from "https://deno.land/x/imagescript@1.3.0/mod.ts";
1+
import { launch } from "astral";
2+
import { Image } from "imagescript";
33

44
if (Deno.args.length !== 2) {
55
throw new Error("Usage: screenshot <url> <id>");
@@ -11,20 +11,22 @@ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
1111
throw new Error("Invalid URL");
1212
}
1313

14-
const browser = await puppeteer.launch({
15-
defaultViewport: { width: 1200, height: 675 },
16-
headless: true,
17-
});
18-
const page = await browser.newPage();
19-
await page.goto(url, { waitUntil: "networkidle2" });
14+
const browser = await launch();
15+
const page = await browser.newPage(url);
16+
await page.waitForNetworkIdle();
2017
const raw = await page.screenshot();
18+
2119
await browser.close();
2220

2321
// convert to jpeg
2422
const image2x = await Image.decode(raw);
25-
const jpeg2x = import.meta.resolve(`../static/showcase/${id}2x.jpg`);
26-
await Deno.writeFile(jpeg2x, await image2x.encodeJPEG(80));
23+
await Deno.writeFile(
24+
`./www/static/showcase/${id}2x.jpg`,
25+
await image2x.encodeJPEG(80),
26+
);
2727

28-
const jpeg1x = import.meta.resolve(`../static/showcase/${id}1x.jpg`);
2928
const image1x = image2x.resize(image2x.width / 2, Image.RESIZE_AUTO);
30-
await Deno.writeFile(jpeg1x, await image1x.encodeJPEG(80));
29+
await Deno.writeFile(
30+
`./www/static/showcase/${id}1x.jpg`,
31+
await image1x.encodeJPEG(80),
32+
);

0 commit comments

Comments
 (0)