kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Playwright + Puppeteer fix for when page is taller than viewport but less than screenshot step_size (#3113)
rodzic
3a583a4e5d
commit
079efd0a85
|
@ -26,9 +26,11 @@ def capture_full_page(page):
|
||||||
step_size = SCREENSHOT_SIZE_STITCH_THRESHOLD # Size that won't cause GPU to overflow
|
step_size = SCREENSHOT_SIZE_STITCH_THRESHOLD # Size that won't cause GPU to overflow
|
||||||
screenshot_chunks = []
|
screenshot_chunks = []
|
||||||
y = 0
|
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 > 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
|
# Set viewport to a larger size to capture more content at once
|
||||||
page.set_viewport_size({'width': page.viewport_size['width'], 'height': step_size})
|
page.set_viewport_size({'width': page.viewport_size['width'], 'height': step_size})
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,10 @@ async def capture_full_page(page):
|
||||||
screenshot_chunks = []
|
screenshot_chunks = []
|
||||||
y = 0
|
y = 0
|
||||||
if page_height > page.viewport['height']:
|
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})
|
await page.setViewport({'width': page.viewport['width'], 'height': step_size})
|
||||||
|
|
||||||
|
|
||||||
while y < min(page_height, SCREENSHOT_MAX_TOTAL_HEIGHT):
|
while y < min(page_height, SCREENSHOT_MAX_TOTAL_HEIGHT):
|
||||||
await page.evaluate(f"window.scrollTo(0, {y})")
|
await page.evaluate(f"window.scrollTo(0, {y})")
|
||||||
screenshot_chunks.append(await page.screenshot(type_='jpeg',
|
screenshot_chunks.append(await page.screenshot(type_='jpeg',
|
||||||
|
|
Ładowanie…
Reference in New Issue