fix: improve image loading logic by waiting for visibility instead of…#53
fix: improve image loading logic by waiting for visibility instead of…#53
Conversation
There was a problem hiding this comment.
Pull Request Overview
Improves image loading logic by replacing network idle waiting with visibility-based detection for more reliable image loading detection.
- Replaces network idle state waiting with waiting for specific image selectors to be visible
- Adds a fixed timeout delay after "Load More" clicks instead of waiting for network idle state
- Updates console logging messages to reflect the new loading detection strategy
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| await loadMoreButton.click(); | ||
|
|
||
| // Wait for new content to load | ||
| await page.waitForLoadState("networkidle"); | ||
| await page.waitForTimeout(5000); |
There was a problem hiding this comment.
Fixed timeout delays can be inefficient and unreliable. Consider using a more robust waiting strategy like page.waitForSelector() with a specific selector for newly loaded images, or page.waitForFunction() to wait for a condition that indicates new content has loaded.
| await page.waitForSelector( | ||
| 'img[src^="https://images.pexels.com/photos/"]', | ||
| { | ||
| state: "visible", | ||
| timeout: 60000, | ||
| }, | ||
| ); |
There was a problem hiding this comment.
The hardcoded URL prefix 'https://images.pexels.com/photos/' creates tight coupling to a specific domain. Consider extracting this as a configuration constant or parameter to improve maintainability and reusability.
… network idle