Skip to content

Commit

Permalink
Merge pull request #2 from codante-io/screenshot-wait-time
Browse files Browse the repository at this point in the history
wait for animations
  • Loading branch information
robertotcestari authored Sep 19, 2024
2 parents ca9da55 + da7ef38 commit 4578cf5
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 = 1500 // 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 4578cf5

Please sign in to comment.