MCPcopy
hub / github.com/freshframework/fresh / captureScreenshot

Function captureScreenshot

www/utils/screenshot.ts:28–47  ·  view source on GitHub ↗
(
  url: string,
  id: string,
)

Source from the content-addressed store, hash-verified

26}
27
28export 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
50if (import.meta.main) {

Callers 1

screenshot.tsFile · 0.85

Calls 2

generateFilePathsFunction · 0.85
closeMethod · 0.65

Tested by

no test coverage detected