Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(maxun-core): add multiple scroll approach #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RohitR311 wants to merge 1 commit into develop
base: develop
Choose a base branch
Loading
from ytscroll-fix

Conversation

Copy link
Collaborator

@RohitR311 RohitR311 commented Aug 28, 2025
edited by coderabbitai bot
Loading

What this PR does?

Brings in support for one more scroll approach just in case the original one fails as it seems to be not supported for certain sites like www.youtube.com

Fixes: #759

Summary by CodeRabbit

  • Bug Fixes
    • Auto-scroll now consistently reaches the true bottom of pages, reducing missed content.
    • Improved handling of pages with complex or dynamically changing layouts.
    • More reliable behavior when navigating paginated content, minimizing stalls or partial loads.
    • Smoother end-of-page detection for long documents and feeds.

@RohitR311 RohitR311 added Type: Bug Something isn't working Scope: Ext Issues/PRs related to core extraction labels Aug 28, 2025
Copy link

coderabbitai bot commented Aug 28, 2025
edited
Loading

Walkthrough

Replaced bottom-scroll and height-detection logic in maxun-core/src/interpret.ts to compute page height using Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) across main and pagination paths. Updated currentHeight helpers accordingly. No exported signatures changed; control flow remains the same.

Changes

Cohort / File(s) Summary
Scrolling height computation updates
maxun-core/src/interpret.ts
Replaced uses of document.body.scrollHeight with max of body and documentElement scrollHeight, updated currentHeight helpers, and adjusted scroll-to-bottom calls to use the computed max height. No API/signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix pagination scroll failures where window.scrollTo is unsupported (#{759}) The changes continue using window.scrollTo; no fallback or alternative mechanism is introduced.

Poem

I stretched my ears to the page’s tall sky,
Hopped to the max where pixels lie.
No more guessing the viewport’s end—
I measure both roots, around the bend.
Scroll, scroll, little paws glide—
To the tallest carrot on the website ride! 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ytscroll-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
maxun-core/src/interpret.ts (1)

781-801: scrollUp path also needs container-aware fallback and measurement

window.scrollTo(0, 0) + documentElement.scrollTop will fail on inner scrollers (e.g., YouTube). Mirror the multi-approach logic and read the active scroller’s scrollTop.

- await page.evaluate(() => window.scrollTo(0, 0));
+ await page.evaluate(() => {
+ if (typeof window.scrollUp === 'function') {
+ window.scrollUp(1);
+ return;
+ }
+ const main = document.scrollingElement || document.documentElement || document.body;
+ if (typeof main.scrollTo === 'function') main.scrollTo(0, 0);
+ else (main as any).scrollTop = 0;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ if (best) {
+ if (typeof (best as any).scrollTo === 'function') (best as any).scrollTo(0, 0);
+ else (best as any).scrollTop = 0;
+ }
+ });
- const currentTopHeight = await page.evaluate(() => document.documentElement.scrollTop);
+ const currentTopHeight = await page.evaluate(() => {
+ const main = document.scrollingElement || document.documentElement || document.body;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ const el = (best ?? main) as HTMLElement;
+ return el.scrollTop;
+ });
🧹 Nitpick comments (2)
maxun-core/src/interpret.ts (2)

514-519: Unify "scroll" action with the new multi-approach

Keep the action consistent with pagination paths so user-invoked scroll benefits from the fallback too.

- await page.evaluate(async (pagesInternal) => {
- for (let i = 1; i <= (pagesInternal ?? 1); i += 1) {
- // @ts-ignore
- window.scrollTo(0, window.scrollY + window.innerHeight);
- }
- }, pages ?? 1);
+ await page.evaluate(async (pagesInternal) => {
+ const times = pagesInternal ?? 1;
+ for (let i = 0; i < times; i += 1) {
+ if (typeof window.scrollDown === 'function') {
+ window.scrollDown(1);
+ continue;
+ }
+ const main = document.scrollingElement || document.documentElement || document.body;
+ if (typeof main.scrollBy === 'function') main.scrollBy(0, main.clientHeight);
+ else (main as any).scrollTop += (main as any).clientHeight || window.innerHeight;
+ }
+ }, pages ?? 1);

737-769: Replace fixed 2s sleeps after scrolls with waitForFunction

Detected three occurrences of await page.waitForTimeout(2000) immediately after window.scrollTo in maxun-core/src/interpret.ts:

  • lines 743–745
  • lines 781–783
  • lines 1045–1047

Consider replacing each with something like:

- await page.waitForTimeout(2000);
+ await page.waitForFunction(() => {
+ const el = (document.scrollingElement || document.documentElement || document.body) as HTMLElement;
+ return el.scrollTop + el.clientHeight >= el.scrollHeight - 2;
+ }, { timeout: 3000 }).catch(() => {});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4b68efb and 49b0c48.

📒 Files selected for processing (1)
  • maxun-core/src/interpret.ts (2 hunks)

Comment on lines +737 to 745
await page.evaluate(() => {
const scrollHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);

window.scrollTo(0, scrollHeight);
});
await page.waitForTimeout(2000);
Copy link

@coderabbitai coderabbitai bot Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Still relying on window.scrollTo; add real fallback or delegate to window.scrollDown to meet PR objective

On sites like youtube.com the scrollable container isn’t window; this will no-op. Either call the injected window.scrollDown (which can encapsulate multi-approach logic) or implement a container-aware fallback here.

Apply one of the following diffs (Option A preferred):

Option A — delegate to injected helper:

- await page.evaluate(() => {
- const scrollHeight = Math.max(
- document.body.scrollHeight,
- document.documentElement.scrollHeight
- );
-
- window.scrollTo(0, scrollHeight);
- });
+ await page.evaluate(() => {
+ if (typeof window.scrollDown === 'function') {
+ window.scrollDown(1);
+ return;
+ }
+ const main = document.scrollingElement || document.documentElement || document.body;
+ if (typeof main.scrollTo === 'function') main.scrollTo(0, main.scrollHeight);
+ else (main as any).scrollTop = main.scrollHeight;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ if (best) {
+ if (typeof (best as any).scrollTo === 'function') (best as any).scrollTo(0, best.scrollHeight);
+ else (best as any).scrollTop = best.scrollHeight;
+ }
+ });
📝 Committable suggestion

!!️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await page.evaluate(() => {
const scrollHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);
window.scrollTo(0, scrollHeight);
});
await page.waitForTimeout(2000);
await page.evaluate(() => {
if (typeof window.scrollDown === 'function') {
window.scrollDown(1);
return;
}
const main = document.scrollingElement || document.documentElement || document.body;
if (typeof main.scrollTo === 'function') main.scrollTo(0, main.scrollHeight);
else (main as any).scrollTop = main.scrollHeight;
const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
const best = scrollables
.filter(el => {
const s = getComputedStyle(el);
return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
})
.sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
if (best) {
if (typeof (best as any).scrollTo === 'function') (best as any).scrollTo(0, best.scrollHeight);
else (best as any).scrollTop = best.scrollHeight;
}
});
await page.waitForTimeout(2000);
🤖 Prompt for AI Agents
In maxun-core/src/interpret.ts around lines 737 to 745, the code uses
window.scrollTo which no-ops on sites where the scrollable container is not
window (e.g., YouTube); replace the direct window.scrollTo call with a call to
the injected helper window.scrollDown (preferred) so the page-level script can
choose the correct container and perform multi-step scrolling, or implement a
container-aware fallback here by locating the nearest scrollable element
(checking document.scrollingElement, document.body, and overflowed descendants)
and scrolling that element to its scrollHeight instead; ensure you await the
evaluated helper and keep the waitForTimeout(2000) after the delegated/fallback
scroll.

Comment on lines +747 to 753
const currentHeight = await page.evaluate(() => {
return Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);
});
const currentResultCount = allResults.length;
Copy link

@coderabbitai coderabbitai bot Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Height check ignores inner scroll containers; track the active scroller’s height

Comparing only body/documentElement heights will prematurely stop on pages with inner scrolling containers.

Apply:

- const currentHeight = await page.evaluate(() => {
- return Math.max(
- document.body.scrollHeight,
- document.documentElement.scrollHeight
- );
- });
+ const currentHeight = await page.evaluate(() => {
+ const main = document.scrollingElement || document.documentElement || document.body;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ const el = (best ?? main) as HTMLElement;
+ return el.scrollHeight;
+ });
📝 Committable suggestion

!!️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const currentHeight = await page.evaluate(() => {
return Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);
});
const currentResultCount = allResults.length;
const currentHeight = await page.evaluate(() => {
const main = document.scrollingElement || document.documentElement || document.body;
const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
const best = scrollables
.filter(el => {
const s = getComputedStyle(el);
return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
})
.sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
const el = (best ?? main) as HTMLElement;
return el.scrollHeight;
});
const currentResultCount = allResults.length;

Comment on lines +1040 to +1046
const scrollHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);

window.scrollTo(0, scrollHeight);
});
Copy link

@coderabbitai coderabbitai bot Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Load-more flow: same window.scrollTo limitation — use helper/fallback scrolling

Mirror the scrollDown fix here; otherwise "Load more" pages with inner scrollers won’t advance.

- await page.evaluate(() => {
- const scrollHeight = Math.max(
- document.body.scrollHeight,
- document.documentElement.scrollHeight
- );
-
- window.scrollTo(0, scrollHeight);
- });
+ await page.evaluate(() => {
+ if (typeof window.scrollDown === 'function') {
+ window.scrollDown(1);
+ return;
+ }
+ const main = document.scrollingElement || document.documentElement || document.body;
+ if (typeof main.scrollTo === 'function') main.scrollTo(0, main.scrollHeight);
+ else (main as any).scrollTop = main.scrollHeight;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ if (best) {
+ if (typeof (best as any).scrollTo === 'function') (best as any).scrollTo(0, best.scrollHeight);
+ else (best as any).scrollTop = best.scrollHeight;
+ }
+ });
🤖 Prompt for AI Agents
In maxun-core/src/interpret.ts around lines 1040 to 1046, the code calls
window.scrollTo(0, scrollHeight) which fails for pages that use inner scrollable
containers; replace this direct window.scrollTo with the same scrollDown
helper/fallback used elsewhere (or implement the equivalent: detect the deepest
scrollable element, scroll that element to its max scrollTop, and fall back to
window.scrollTo if none found). Ensure you call or await the helper correctly
and remove the direct window.scrollTo call so "Load more" flows advance inner
scrollers as well as the window.

Comment on lines +1049 to +1054
const currentHeight = await page.evaluate(() => {
return Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);
});
Copy link

@coderabbitai coderabbitai bot Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Load-more height measurement should use the active scroller

Align measurement with the scrolling target to avoid false "no more items" detections.

- const currentHeight = await page.evaluate(() => {
- return Math.max(
- document.body.scrollHeight,
- document.documentElement.scrollHeight
- );
- });
+ const currentHeight = await page.evaluate(() => {
+ const main = document.scrollingElement || document.documentElement || document.body;
+ const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
+ const best = scrollables
+ .filter(el => {
+ const s = getComputedStyle(el);
+ return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
+ })
+ .sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
+ const el = (best ?? main) as HTMLElement;
+ return el.scrollHeight;
+ });
📝 Committable suggestion

!!️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const currentHeight = await page.evaluate(() => {
return Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight
);
});
const currentHeight = await page.evaluate(() => {
const main = document.scrollingElement || document.documentElement || document.body;
const scrollables = Array.from(document.querySelectorAll('*')) as HTMLElement[];
const best = scrollables
.filter(el => {
const s = getComputedStyle(el);
return (s.overflowY === 'auto' || s.overflowY === 'scroll') && el.scrollHeight > el.clientHeight;
})
.sort((a, b) => b.scrollHeight - a.scrollHeight)[0];
const el = (best ?? main) as HTMLElement;
return el.scrollHeight;
});
🤖 Prompt for AI Agents
In maxun-core/src/interpret.ts around lines 1049 to 1054, the height measurement
uses document.body/documentElement which can mismatch the actual scrolling
container; change the evaluation to measure the active scroller (use
document.scrollingElement if available or the specific scroller element used for
scroll actions). Update the page.evaluate to query the active scroller (falling
back to document.scrollingElement or a known scroller selector), and return its
scrollHeight (or bounding height) instead of
document.body/document.documentElement so load-more detection aligns with the
element being scrolled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

@amhsirak amhsirak amhsirak approved these changes

Assignees
No one assigned
Labels
Scope: Ext Issues/PRs related to core extraction Type: Bug Something isn't working
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: Scroll paginations failure on some sites

AltStyle によって変換されたページ (->オリジナル) /