Skip to content

Commit 7d27557

Browse files
authored
Merge pull request #760 from getmaxun/ytscroll-fix
fix(maxun-core): add multiple scroll approach
2 parents 24fd059 + 49b0c48 commit 7d27557

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

maxun-core/src/interpret.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,22 @@ export default class Interpreter extends EventEmitter {
734734
return allResults;
735735
}
736736

737-
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
737+
await page.evaluate(() => {
738+
const scrollHeight = Math.max(
739+
document.body.scrollHeight,
740+
document.documentElement.scrollHeight
741+
);
742+
743+
window.scrollTo(0, scrollHeight);
744+
});
738745
await page.waitForTimeout(2000);
739746

740-
const currentHeight = await page.evaluate(() => document.body.scrollHeight);
747+
const currentHeight = await page.evaluate(() => {
748+
return Math.max(
749+
document.body.scrollHeight,
750+
document.documentElement.scrollHeight
751+
);
752+
});
741753
const currentResultCount = allResults.length;
742754

743755
if (currentResultCount === previousResultCount) {
@@ -1024,10 +1036,22 @@ export default class Interpreter extends EventEmitter {
10241036

10251037
// Wait for content to load and check scroll height
10261038
await page.waitForTimeout(2000);
1027-
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
1039+
await page.evaluate(() => {
1040+
const scrollHeight = Math.max(
1041+
document.body.scrollHeight,
1042+
document.documentElement.scrollHeight
1043+
);
1044+
1045+
window.scrollTo(0, scrollHeight);
1046+
});
10281047
await page.waitForTimeout(2000);
1029-
1030-
const currentHeight = await page.evaluate(() => document.body.scrollHeight);
1048+
1049+
const currentHeight = await page.evaluate(() => {
1050+
return Math.max(
1051+
document.body.scrollHeight,
1052+
document.documentElement.scrollHeight
1053+
);
1054+
});
10311055
const heightChanged = currentHeight !== previousHeight;
10321056
previousHeight = currentHeight;
10331057

0 commit comments

Comments
 (0)