( url: string, id: string, )
| 26 | } |
| 27 | |
| 28 | export async function captureScreenshot( |
| 29 | url: string, |
| 30 | id: string, |
| 31 | ): Promise<void> { |
| 32 | const browser = await launch(); |
| 33 | try { |
| 34 | const page = await browser.newPage(url); |
| 35 | await page.waitForNetworkIdle(); |
| 36 | const raw = await page.screenshot(); |
| 37 | |
| 38 | const image2x = await Image.decode(raw); |
| 39 | const { image2x: path2x, image1x: path1x } = generateFilePaths(id); |
| 40 | |
| 41 | await Deno.writeFile(path2x, await image2x.encodeJPEG(80)); |
| 42 | const image1x = image2x.resize(image2x.width / 2, Image.RESIZE_AUTO); |
| 43 | await Deno.writeFile(path1x, await image1x.encodeJPEG(80)); |
| 44 | } finally { |
| 45 | await browser.close(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // only run the script if it's the main module |
| 50 | if (import.meta.main) { |
no test coverage detected