From b598d265b2c4e93fd919ca307c5d7caba54495e3 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 20 Sep 2024 20:26:51 +0530 Subject: [PATCH] feat: scroll up --- maxun-core/src/interpret.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/maxun-core/src/interpret.ts b/maxun-core/src/interpret.ts index 4068f7be..8a5b3788 100644 --- a/maxun-core/src/interpret.ts +++ b/maxun-core/src/interpret.ts @@ -406,6 +406,17 @@ export default class Interpreter extends EventEmitter { previousHeight = currentHeight; break; case 'scrollUp': + await page.evaluate(() => window.scrollTo(0, 0)); + await page.waitForTimeout(2000); + + const currentTopHeight = await page.evaluate(() => document.documentElement.scrollTop); + if (currentTopHeight === 0) { + const finalResults = await page.evaluate((cfg) => window.scrapeList(cfg), config); + allResults = allResults.concat(finalResults); + return allResults; + } + + previousHeight = currentTopHeight; break; case 'clickNext': const pageResults = await page.evaluate((cfg) => window.scrapeList(cfg), config);