Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"dev": "ts-node src/main.ts"
},
"dependencies": {
"@sparticuz/chromium": "^141.0.0",
"playwright": "^1.40.0"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.155",
"@types/node": "^20.0.0",
"ts-node": "^10.9.0",
"typescript": "^5.0.0",
"@sparticuz/chromium": "^141.0.0"
"typescript": "^5.0.0"
},
"packageManager": "yarn@1.22.0",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions scripts/src/lambda-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function lambdaHandler(
const imageLinks = await getImageLinksPlaywright(pexelsUrl);

if (imageLinks && imageLinks.length > 0) {
console.log(`Total image links found: ${imageLinks.length}`);
return {
statusCode: 200,
body: JSON.stringify({
Expand All @@ -29,6 +30,7 @@ export async function lambdaHandler(
}),
};
} else {
console.log("No image links found");
return {
statusCode: 200,
body: JSON.stringify({
Expand All @@ -40,6 +42,7 @@ export async function lambdaHandler(
};
}
} catch (error) {
console.log(`Error in lambdaHandler: ${error}`);
return {
statusCode: 500,
body: JSON.stringify({
Expand Down
8 changes: 6 additions & 2 deletions scripts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ async function getImageLinksPlaywright(url: string): Promise<string[]> {
timeout: 60000,
});

await page.waitForTimeout(5000);
console.log("Waiting for network idle...");
await page.waitForLoadState("networkidle");
console.log("Page loaded.");

const maxClicks = 5;
let clickCount = 0;
Expand All @@ -94,7 +96,8 @@ async function getImageLinksPlaywright(url: string): Promise<string[]> {
await loadMoreButton.click();

// Wait for new content to load
await page.waitForTimeout(2000);
await page.waitForLoadState("networkidle");
console.log("New content loaded after clicking Load More.");
} catch (error) {
console.error(`Error clicking button: ${error}`);
break;
Expand All @@ -112,6 +115,7 @@ async function getImageLinksPlaywright(url: string): Promise<string[]> {
// Extract image links
const imgLinks = await page.evaluate((): string[] => {
const imgs = Array.from(document.querySelectorAll("img"));
console.log(`Total images found on page: ${imgs.length}`);
const links: string[] = [];

imgs.forEach((img) => {
Expand Down