Skip to content

Commit

Permalink
wait for animations
Browse files Browse the repository at this point in the history
  • Loading branch information
robertotcestari committed Sep 19, 2024
1 parent ca9da55 commit 2d84161
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import sharp from 'sharp';

export async function getBufferFromPageScreenshot(
url: string,
timeout = 30000
timeout = 30000,
animationWaitTime = 1000 // Added animation wait time parameter
) {
// Added timeout parameter with default value
try {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setViewportSize({ width: 1920, height: 1080 });

await page.goto(url, { timeout, waitUntil: 'domcontentloaded' }); // Added timeout option to page.goto()
let screenshotBuffer = await page.screenshot({ timeout }); // Added timeout option to page.screenshot()
await page.goto(url, { timeout, waitUntil: 'domcontentloaded' });
await page.waitForTimeout(animationWaitTime); // Added wait for animations

let screenshotBuffer = await page.screenshot({ timeout });
await browser.close();

const image = sharp(screenshotBuffer);
Expand Down

0 comments on commit 2d84161

Please sign in to comment.