From 378c4b570be61104d280bc5e092ba07fbcd4004d Mon Sep 17 00:00:00 2001 From: Perry Zhu Date: Mon, 13 Oct 2025 12:24:01 -0700 Subject: [PATCH] fix: improve image loading logic by waiting for visibility instead of network idle --- scripts/src/main.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/src/main.ts b/scripts/src/main.ts index d56c196..d9f5a44 100644 --- a/scripts/src/main.ts +++ b/scripts/src/main.ts @@ -76,9 +76,15 @@ async function getImageLinksPlaywright(url: string): Promise { timeout: 60000, }); - console.log("Waiting for network idle..."); - await page.waitForLoadState("networkidle"); - console.log("Page loaded."); + console.log("Waiting for image grid to be visible..."); + await page.waitForSelector( + 'img[src^="https://images.pexels.com/photos/"]', + { + state: "visible", + timeout: 60000, + }, + ); + console.log("Page content is ready."); const maxClicks = 5; let clickCount = 0; @@ -94,9 +100,7 @@ async function getImageLinksPlaywright(url: string): Promise { ); clickCount++; await loadMoreButton.click(); - - // Wait for new content to load - await page.waitForLoadState("networkidle"); + await page.waitForTimeout(5000); console.log("New content loaded after clicking Load More."); } catch (error) { console.error(`Error clicking button: ${error}`);