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](https://github.com/lucacasonato/deno-puppeteer/issues/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>
This commit is contained in:
zhizheng
2025-05-12 20:02:15 +02:00
committed by GitHub
co-authored by 李嘉图·M·路 Asher Gomez
parent 09705b9b7f
commit d68b5ecd5b
3 changed files with 42 additions and 111 deletions
Generated
+26 -99
View File
@@ -1,55 +1,40 @@
{
"version": "5",
"specifiers": {
"jsr:@astral/astral@~0.5.2": "0.5.2",
"jsr:@astral/astral@~0.5.2": "0.5.3",
"jsr:@deno-library/progress@^1.5.1": "1.5.1",
"jsr:@deno/cache-dir@0.14": "0.14.0",
"jsr:@deno/doc@0.172": "0.172.0",
"jsr:@deno/otel@*": "0.0.2",
"jsr:@fresh/core@^2.0.0-alpha.26": "2.0.0-alpha.29",
"jsr:@luca/esbuild-deno-loader@0.11": "0.11.1",
"jsr:@marvinh-test/fresh-island@*": "0.0.1",
"jsr:@marvinh-test/fresh-island@^0.0.1": "0.0.1",
"jsr:@std/assert@^1.0.12": "1.0.13",
"jsr:@std/async@1": "1.0.12",
"jsr:@std/bytes@^1.0.2": "1.0.5",
"jsr:@std/bytes@^1.0.5": "1.0.5",
"jsr:@std/cli@1": "1.0.17",
"jsr:@std/cli@^1.0.17": "1.0.17",
"jsr:@std/collections@^1.0.11": "1.0.11",
"jsr:@std/crypto@1": "1.0.4",
"jsr:@std/data-structures@^1.0.6": "1.0.7",
"jsr:@std/datetime@~0.225.2": "0.225.4",
"jsr:@std/encoding@1": "1.0.10",
"jsr:@std/encoding@^1.0.10": "1.0.10",
"jsr:@std/encoding@^1.0.5": "1.0.10",
"jsr:@std/expect@1": "1.0.15",
"jsr:@std/fmt@1": "1.0.7",
"jsr:@std/fmt@1.0.3": "1.0.3",
"jsr:@std/fmt@^1.0.3": "1.0.7",
"jsr:@std/fmt@^1.0.7": "1.0.7",
"jsr:@std/front-matter@^1.0.5": "1.0.9",
"jsr:@std/fs@1": "1.0.17",
"jsr:@std/fs@^1.0.16": "1.0.17",
"jsr:@std/fs@^1.0.6": "1.0.17",
"jsr:@std/html@1": "1.0.3",
"jsr:@std/html@^1.0.3": "1.0.3",
"jsr:@std/http@^1.0.15": "1.0.15",
"jsr:@std/internal@^1.0.6": "1.0.6",
"jsr:@std/io@0.225": "0.225.0",
"jsr:@std/io@0.225.0": "0.225.0",
"jsr:@std/json@^1.0.2": "1.0.2",
"jsr:@std/jsonc@1": "1.0.2",
"jsr:@std/media-types@1": "1.1.0",
"jsr:@std/media-types@^1.1.0": "1.1.0",
"jsr:@std/net@^1.0.4": "1.0.4",
"jsr:@std/path@1": "1.0.9",
"jsr:@std/path@^1.0.6": "1.0.9",
"jsr:@std/path@^1.0.8": "1.0.9",
"jsr:@std/path@^1.0.9": "1.0.9",
"jsr:@std/semver@1": "1.0.5",
"jsr:@std/streams@1": "1.0.9",
"jsr:@std/streams@^1.0.9": "1.0.9",
"jsr:@std/testing@1": "1.0.11",
"jsr:@std/toml@^1.0.3": "1.0.5",
"jsr:@std/yaml@^1.0.5": "1.0.6",
@@ -57,8 +42,8 @@
"npm:@opentelemetry/api@1": "1.9.0",
"npm:@opentelemetry/api@^1.9.0": "1.9.0",
"npm:@opentelemetry/sdk-trace-base@1": "1.30.1_@opentelemetry+api@1.9.0",
"npm:@preact/signals@^1.2.3": "1.3.2_preact@10.26.5",
"npm:@preact/signals@^1.3.0": "1.3.2_preact@10.26.5",
"npm:@preact/signals@^1.2.3": "1.3.2_preact@10.26.6",
"npm:@preact/signals@^1.3.0": "1.3.2_preact@10.26.6",
"npm:@types/node@*": "22.12.0",
"npm:autoprefixer@10.4.17": "10.4.17_postcss@8.4.35",
"npm:cssnano@6.0.3": "6.0.3_postcss@8.4.35",
@@ -69,17 +54,17 @@
"npm:marked-mangle@^1.1.9": "1.1.10_marked@14.1.4",
"npm:marked@^14.1.2": "14.1.4",
"npm:postcss@8.4.35": "8.4.35",
"npm:preact-render-to-string@^6.5.11": "6.5.13_preact@10.26.5",
"npm:preact@^10.22.0": "10.26.5",
"npm:preact@^10.24.1": "10.26.5",
"npm:preact@^10.25.1": "10.26.5",
"npm:preact-render-to-string@^6.5.11": "6.5.13_preact@10.26.6",
"npm:preact@^10.22.0": "10.26.6",
"npm:preact@^10.24.1": "10.26.6",
"npm:preact@^10.25.1": "10.26.6",
"npm:prismjs@^1.29.0": "1.30.0",
"npm:tailwindcss@^3.4.1": "3.4.17_postcss@8.5.3",
"npm:ts-morph@22": "22.0.0"
},
"jsr": {
"@astral/astral@0.5.2": {
"integrity": "dc4b7e0ea5d8186fcd9e33e2c54e62913d7eb99d5a2d4f987b1c5399d8e295de",
"@astral/astral@0.5.3": {
"integrity": "d6a4628313d8be99aac0f51005c1dc090fa3b4c6b5c8335c26a52d4842aa1276",
"dependencies": [
"jsr:@deno-library/progress",
"jsr:@std/async",
@@ -92,22 +77,7 @@
"integrity": "966611826b8bb27baae73ab1c4fa4317cd4edd2abb99750cd6f8488d22d5b121",
"dependencies": [
"jsr:@std/fmt@1.0.3",
"jsr:@std/io@0.225.0"
]
},
"@deno/cache-dir@0.14.0": {
"integrity": "729f0b68e7fc96443c09c2c544b830ca70897bdd5168598446d752f7a4c731ad",
"dependencies": [
"jsr:@std/fmt@^1.0.3",
"jsr:@std/fs@^1.0.6",
"jsr:@std/io@0.225",
"jsr:@std/path@^1.0.8"
]
},
"@deno/doc@0.172.0": {
"integrity": "72a68ed533576a06feb930a84784ad9ba6d83ca9d581fc734d498c58e32b7cf5",
"dependencies": [
"jsr:@deno/cache-dir"
"jsr:@std/io"
]
},
"@deno/otel@0.0.2": {
@@ -117,31 +87,10 @@
"npm:@opentelemetry/sdk-trace-base"
]
},
"@fresh/core@2.0.0-alpha.29": {
"integrity": "5374a478c2d407da2a84a9802e00da2305de2945b0934e6a7b24a989a7b82e0f",
"dependencies": [
"jsr:@luca/esbuild-deno-loader",
"jsr:@std/crypto",
"jsr:@std/datetime",
"jsr:@std/encoding@1",
"jsr:@std/fmt@1",
"jsr:@std/fs@1",
"jsr:@std/html@1",
"jsr:@std/jsonc",
"jsr:@std/media-types@1",
"jsr:@std/path@1",
"jsr:@std/semver",
"npm:@opentelemetry/api@^1.9.0",
"npm:esbuild",
"npm:esbuild-wasm",
"npm:preact-render-to-string",
"npm:preact@^10.25.1"
]
},
"@luca/esbuild-deno-loader@0.11.1": {
"integrity": "dc020d16d75b591f679f6b9288b10f38bdb4f24345edb2f5732affa1d9885267",
"dependencies": [
"jsr:@std/bytes@^1.0.2",
"jsr:@std/bytes",
"jsr:@std/encoding@^1.0.5",
"jsr:@std/path@^1.0.6"
]
@@ -175,9 +124,6 @@
"@std/crypto@1.0.4": {
"integrity": "cee245c453bd5366207f4d8aa25ea3e9c86cecad2be3fefcaa6cb17203d79340"
},
"@std/data-structures@1.0.7": {
"integrity": "16932d2c8d281f65eaaa2209af2473209881e33b1ced54cd1b015e7b4cdbb0d2"
},
"@std/datetime@0.225.4": {
"integrity": "682bc21738b941a4ed1465be6da01704e8010a3a6d9b615de9458202b84e00ec"
},
@@ -214,26 +160,13 @@
"integrity": "7a0ac35e050431fb49d44e61c8b8aac1ebd55937e0dc9ec6409aa4bab39a7988"
},
"@std/http@1.0.15": {
"integrity": "435a4934b4e196e82a8233f724da525f7b7112f3566502f28815e94764c19159",
"dependencies": [
"jsr:@std/cli@^1.0.17",
"jsr:@std/encoding@^1.0.10",
"jsr:@std/fmt@^1.0.7",
"jsr:@std/html@^1.0.3",
"jsr:@std/media-types@^1.1.0",
"jsr:@std/net",
"jsr:@std/path@^1.0.9",
"jsr:@std/streams@^1.0.9"
]
"integrity": "435a4934b4e196e82a8233f724da525f7b7112f3566502f28815e94764c19159"
},
"@std/internal@1.0.6": {
"integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4"
},
"@std/io@0.225.0": {
"integrity": "c1db7c5e5a231629b32d64b9a53139445b2ca640d828c26bf23e1c55f8c079b3",
"dependencies": [
"jsr:@std/bytes@^1.0.2"
]
"integrity": "c1db7c5e5a231629b32d64b9a53139445b2ca640d828c26bf23e1c55f8c079b3"
},
"@std/json@1.0.2": {
"integrity": "d9e5497801c15fb679f55a2c01c7794ad7a5dfda4dd1bebab5e409cb5e0d34d4"
@@ -247,9 +180,6 @@
"@std/media-types@1.1.0": {
"integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4"
},
"@std/net@1.0.4": {
"integrity": "2f403b455ebbccf83d8a027d29c5a9e3a2452fea39bb2da7f2c04af09c8bc852"
},
"@std/path@1.0.9": {
"integrity": "260a49f11edd3db93dd38350bf9cd1b4d1366afa98e81b86167b4e3dd750129e"
},
@@ -257,16 +187,12 @@
"integrity": "529f79e83705714c105ad0ba55bec0f9da0f24d2f726b6cc1c15e505cc2c0624"
},
"@std/streams@1.0.9": {
"integrity": "a9d26b1988cdd7aa7b1f4b51e1c36c1557f3f252880fa6cc5b9f37078b1a5035",
"dependencies": [
"jsr:@std/bytes@^1.0.5"
]
"integrity": "a9d26b1988cdd7aa7b1f4b51e1c36c1557f3f252880fa6cc5b9f37078b1a5035"
},
"@std/testing@1.0.11": {
"integrity": "12b3db12d34f0f385a26248933bde766c0f8c5ad8b6ab34d4d38f528ab852f48",
"dependencies": [
"jsr:@std/assert",
"jsr:@std/data-structures",
"jsr:@std/fs@^1.0.16",
"jsr:@std/internal",
"jsr:@std/path@^1.0.8"
@@ -497,7 +423,7 @@
"@preact/signals-core@1.8.0": {
"integrity": "sha512-OBvUsRZqNmjzCZXWLxkZfhcgT+Fk8DDcT/8vD6a1xhDemodyy87UJRJfASMuSD8FaAIeGgGm85ydXhm7lr4fyA=="
},
"@preact/signals@1.3.2_preact@10.26.5": {
"@preact/signals@1.3.2_preact@10.26.6": {
"integrity": "sha512-naxcJgUJ6BTOROJ7C3QML7KvwKwCXQJYTc5L/b0eEsdYgPB6SxwoQ1vDGcS0Q7GVjAenVq/tXrybVdFShHYZWg==",
"dependencies": [
"@preact/signals-core",
@@ -584,8 +510,8 @@
"fill-range"
]
},
"browserslist@4.24.4": {
"integrity": "sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A==",
"browserslist@4.24.5": {
"integrity": "sha512-FDToo4Wo82hIdgc1CQ+NQD0hEhmpPjrZ3hiUgwgOG6IuTdlpr8jdjyG24P6cNP1yJpTLzS5OcGgSw0xmDU1/Tw==",
"dependencies": [
"caniuse-lite",
"electron-to-chromium",
@@ -606,8 +532,8 @@
"lodash.uniq"
]
},
"caniuse-lite@1.0.30001715": {
"integrity": "sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw=="
"caniuse-lite@1.0.30001717": {
"integrity": "sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw=="
},
"chokidar@3.6.0": {
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
@@ -783,8 +709,8 @@
"eastasianwidth@0.2.0": {
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA=="
},
"electron-to-chromium@1.5.142": {
"integrity": "sha512-Ah2HgkTu/9RhTDNThBtzu2Wirdy4DC9b0sMT1pUhbkZQ5U/iwmE+PHZX1MpjD5IkJCc2wSghgGG/B04szAx07w=="
"electron-to-chromium@1.5.151": {
"integrity": "sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA=="
},
"emoji-regex@8.0.0": {
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
@@ -1350,14 +1276,14 @@
"source-map-js"
]
},
"preact-render-to-string@6.5.13_preact@10.26.5": {
"preact-render-to-string@6.5.13_preact@10.26.6": {
"integrity": "sha512-iGPd+hKPMFKsfpR2vL4kJ6ZPcFIoWZEcBf0Dpm3zOpdVvj77aY8RlLiQji5OMrngEyaxGogeakTb54uS2FvA6w==",
"dependencies": [
"preact"
]
},
"preact@10.26.5": {
"integrity": "sha512-fmpDkgfGU6JYux9teDWLhj9mKN55tyepwYbxHgQuIxbWQzgFg5vk7Mrrtfx7xRxq798ynkY4DDDxZr235Kk+4w=="
"preact@10.26.6": {
"integrity": "sha512-5SRRBinwpwkaD+OqlBDeITlRgvd8I8QlxHJw9AxSdMNV6O+LodN9nUyYGpSF7sadHjs6RzeFShMexC6DbtWr9g=="
},
"prismjs@1.30.0": {
"integrity": "sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw=="
@@ -1537,7 +1463,7 @@
"undici-types@6.20.0": {
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="
},
"update-browserslist-db@1.1.3_browserslist@4.24.4": {
"update-browserslist-db@1.1.3_browserslist@4.24.5": {
"integrity": "sha512-UxhIZQ+QInVdunkDAaiazvvT/+fXL5Osr0JZlJulepYu6Jd7qJtDZjlur0emRlT71EN3ScPoE7gvsuIKKNavKw==",
"dependencies": [
"browserslist",
@@ -1680,6 +1606,7 @@
},
"www": {
"dependencies": [
"jsr:@astral/astral@*",
"jsr:@luca/esbuild-deno-loader@0.11",
"jsr:@std/crypto@1",
"jsr:@std/datetime@0.225.0",
+2
View File
@@ -21,6 +21,7 @@
"@std/path": "jsr:@std/path@1",
"@std/semver": "jsr:@std/semver@1",
"@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",
"astral": "jsr:@astral/astral",
"autoprefixer": "npm:autoprefixer@10.4.17",
"cssnano": "npm:cssnano@6.0.3",
"esbuild": "npm:esbuild@0.23.1",
@@ -30,6 +31,7 @@
"fresh/dev": "../src/dev/mod.ts",
"fresh/runtime": "../src/runtime/shared.ts",
"github-slugger": "npm:github-slugger@^2.0.0",
"imagescript": "https://deno.land/x/imagescript@1.3.0/mod.ts",
"marked": "npm:marked@^14.1.2",
"marked-mangle": "npm:marked-mangle@^1.1.9",
"postcss": "npm:postcss@8.4.35",
+14 -12
View File
@@ -1,5 +1,5 @@
import puppeteer from "npm:puppeteer@24.7.2";
import { Image } from "https://deno.land/x/imagescript@1.3.0/mod.ts";
import { launch } from "astral";
import { Image } from "imagescript";
if (Deno.args.length !== 2) {
throw new Error("Usage: screenshot <url> <id>");
@@ -11,20 +11,22 @@ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
throw new Error("Invalid URL");
}
const browser = await puppeteer.launch({
defaultViewport: { width: 1200, height: 675 },
headless: true,
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle2" });
const browser = await launch();
const page = await browser.newPage(url);
await page.waitForNetworkIdle();
const raw = await page.screenshot();
await browser.close();
// convert to jpeg
const image2x = await Image.decode(raw);
const jpeg2x = import.meta.resolve(`../static/showcase/${id}2x.jpg`);
await Deno.writeFile(jpeg2x, await image2x.encodeJPEG(80));
await Deno.writeFile(
`./www/static/showcase/${id}2x.jpg`,
await image2x.encodeJPEG(80),
);
const jpeg1x = import.meta.resolve(`../static/showcase/${id}1x.jpg`);
const image1x = image2x.resize(image2x.width / 2, Image.RESIZE_AUTO);
await Deno.writeFile(jpeg1x, await image1x.encodeJPEG(80));
await Deno.writeFile(
`./www/static/showcase/${id}1x.jpg`,
await image1x.encodeJPEG(80),
);