Skip to content

Commit

Permalink
Return captured screenshot buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
gramliu committed Nov 29, 2023
1 parent 1144392 commit fcf76ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions apps/agent/src/lib/render/capture_html.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import puppeteer from "puppeteer";

/**
* Captures the rendered HTML as a screenshot.
* Captures the rendered HTML as a screenshot and returns it as a buffer.
*/
export async function captureRenderedHtml(html: string) {
const browser = await puppeteer.launch();
export async function captureRenderedHtml(html: string): Promise<Buffer> {
const browser = await puppeteer.launch({ headless: "new" });
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 });
await page.setContent(html, {
timeout: 60_000,
});
await page.screenshot({ path: "screenshot.png", fullPage: true });
const buffer = await page.screenshot({ fullPage: true });
return buffer;
}

0 comments on commit fcf76ba

Please sign in to comment.