From 079efd0a856ea9c432f9b6183659e245bf68b8f9 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 12 Apr 2025 18:37:59 +0200 Subject: [PATCH] Playwright + Puppeteer fix for when page is taller than viewport but less than screenshot step_size (#3113) --- changedetectionio/content_fetchers/playwright.py | 6 ++++-- changedetectionio/content_fetchers/puppeteer.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/changedetectionio/content_fetchers/playwright.py b/changedetectionio/content_fetchers/playwright.py index b88ae4b2..3e82c807 100644 --- a/changedetectionio/content_fetchers/playwright.py +++ b/changedetectionio/content_fetchers/playwright.py @@ -26,9 +26,11 @@ def capture_full_page(page): step_size = SCREENSHOT_SIZE_STITCH_THRESHOLD # Size that won't cause GPU to overflow screenshot_chunks = [] y = 0 - - # If page height is larger than current viewport, use a larger viewport for better capturing + if page_height > page.viewport_size['height']: + if page_height < step_size: + step_size = page_height # Incase page is bigger than default viewport but smaller than proposed step size + logger.debug(f"Setting bigger viewport to step through large page width W{page.viewport_size['width']}xH{step_size} because page_height > viewport_size") # Set viewport to a larger size to capture more content at once page.set_viewport_size({'width': page.viewport_size['width'], 'height': step_size}) diff --git a/changedetectionio/content_fetchers/puppeteer.py b/changedetectionio/content_fetchers/puppeteer.py index b4f1c6b1..3e39b5e6 100644 --- a/changedetectionio/content_fetchers/puppeteer.py +++ b/changedetectionio/content_fetchers/puppeteer.py @@ -46,9 +46,10 @@ async def capture_full_page(page): screenshot_chunks = [] y = 0 if page_height > page.viewport['height']: + if page_height < step_size: + step_size = page_height # Incase page is bigger than default viewport but smaller than proposed step size await page.setViewport({'width': page.viewport['width'], 'height': step_size}) - while y < min(page_height, SCREENSHOT_MAX_TOTAL_HEIGHT): await page.evaluate(f"window.scrollTo(0, {y})") screenshot_chunks.append(await page.screenshot(type_='jpeg',