This commit is contained in:
@@ -71,6 +71,44 @@ async def screenshot_url_service(decoded_url, full_page=True):
|
||||
# Ensure network has gone quiet so dynamic requests can finish.
|
||||
await page.wait_for_load_state('networkidle', timeout=30000)
|
||||
|
||||
# Scroll to trigger lazy-loaded/infinite content until height stabilizes.
|
||||
await page.evaluate("""async () => {
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
let previousHeight = 0;
|
||||
let stableRounds = 0;
|
||||
const maxRounds = 30;
|
||||
|
||||
for (let i = 0; i < maxRounds; i++) {
|
||||
const currentHeight = Math.max(
|
||||
document.body.scrollHeight,
|
||||
document.documentElement.scrollHeight
|
||||
);
|
||||
|
||||
window.scrollTo(0, currentHeight);
|
||||
await sleep(700);
|
||||
|
||||
const newHeight = Math.max(
|
||||
document.body.scrollHeight,
|
||||
document.documentElement.scrollHeight
|
||||
);
|
||||
|
||||
if (newHeight <= previousHeight && newHeight <= currentHeight) {
|
||||
stableRounds += 1;
|
||||
if (stableRounds >= 2) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
stableRounds = 0;
|
||||
}
|
||||
|
||||
previousHeight = newHeight;
|
||||
}
|
||||
|
||||
// Return to top for a predictable final render before capture.
|
||||
window.scrollTo(0, 0);
|
||||
await sleep(700);
|
||||
}""")
|
||||
|
||||
# Extra settle time so animations/transitions can complete.
|
||||
await page.wait_for_timeout(5000)
|
||||
screenshot_bytes = await page.screenshot(full_page=full_page, type='png')
|
||||
|
||||
Reference in New Issue
Block a user