From 2d84161f304f0a35f0d4806258c2988db38094fb Mon Sep 17 00:00:00 2001 From: Roberto Cestari Date: Thu, 19 Sep 2024 19:03:35 -0300 Subject: [PATCH 1/2] wait for animations --- src/lib/screenshot.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/screenshot.ts b/src/lib/screenshot.ts index 77c47d2..92fe020 100644 --- a/src/lib/screenshot.ts +++ b/src/lib/screenshot.ts @@ -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); From da7ef3837cf1f11523147edf39ce7b568c3a1eba Mon Sep 17 00:00:00 2001 From: Roberto Cestari Date: Thu, 19 Sep 2024 19:04:43 -0300 Subject: [PATCH 2/2] wait 1.5s --- src/lib/screenshot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/screenshot.ts b/src/lib/screenshot.ts index 92fe020..7a93af2 100644 --- a/src/lib/screenshot.ts +++ b/src/lib/screenshot.ts @@ -4,7 +4,7 @@ import sharp from 'sharp'; export async function getBufferFromPageScreenshot( url: string, timeout = 30000, - animationWaitTime = 1000 // Added animation wait time parameter + animationWaitTime = 1500 // Added animation wait time parameter ) { try { const browser = await chromium.launch();