Skip to content

feat: improve selector generation highlighting #591

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
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented May 9, 2025

What this PR does?

  1. Improves list selector and child selector generation
  2. Adds timeout for page to load after successful pagination navigation

Summary by CodeRabbit

  • Improvements
    • Added a brief delay after pagination navigation to ensure page content is fully loaded before proceeding.
    • Enhanced selector generation logic to return more specific selectors when possible, improving accuracy and efficiency in identifying elements.
    • Improved element selection with fallback attempts for more reliable data extraction when initial selectors fail.
  • Chores
    • Removed an unused variable to streamline the codebase.

@RohitR311 RohitR311 added Type: Enhancement Improvements to existing features Scope: Ext Issues/PRs related to core extraction labels May 9, 2025
Copy link

coderabbitai bot commented May 9, 2025

"""

Walkthrough

The changes introduce an explicit 2-second wait after pagination navigation in the handlePagination method, add early return logic in selector generation functions to shortcut when a class-based selector is detected, remove an unused variable, and add a fallback selector mechanism in scrapeList to improve element querying when nth-child selectors fail. No exported or public API signatures are altered.

Changes

File(s) Change Summary
maxun-core/src/interpret.ts Added a 2-second wait (await page.waitForTimeout(2000)) after successful pagination navigation.
server/src/workflow-management/selector.ts Added early return in selector generation when class selectors are present; removed unused variable.
maxun-core/src/browserSide/scraper.js Added tryFallbackSelector helper in scrapeList to attempt fallback queries for selectors with nth-child.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant handlePagination
    participant page

    User->>handlePagination: Trigger pagination
    handlePagination->>page: Click pagination button
    handlePagination->>page: waitForNavigation
    page-->>handlePagination: Navigation complete
    handlePagination->>page: waitForTimeout(2000)
    handlePagination->>User: Pagination success
Loading
sequenceDiagram
    participant getSelectorPath
    participant DOM
    participant Return

    getSelectorPath->>DOM: Generate non-unique selector
    alt Selector contains '.' and multiple segments
        getSelectorPath->>Return: Return selector early
    else
        getSelectorPath->>DOM: Traverse up DOM for path
        getSelectorPath->>Return: Return constructed path
    end
Loading
sequenceDiagram
    participant scrapeList
    participant tryFallbackSelector
    participant DOM

    scrapeList->>tryFallbackSelector: Query element with selector
    alt Element found
        tryFallbackSelector-->>scrapeList: Return element
    else Selector has nth-child
        tryFallbackSelector->>DOM: Try decremented nth-child selectors
        alt Element found
            tryFallbackSelector-->>scrapeList: Return element
        else
            tryFallbackSelector->>DOM: Try selector without nth-child
            tryFallbackSelector-->>scrapeList: Return element or null
        end
    end
Loading

Possibly related PRs

Suggested reviewers

  • amhsirak

Poem

A hop, a skip, a pause so slight,
Selectors leap with dot-filled might.
Pagination waits, two seconds more,
For pages calm and bugs no more.
Fallbacks try when nth-child hides,
This rabbit codes with eager strides! 🐇✨
"""

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @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

Documentation and Community

  • 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.

@RohitR311 RohitR311 added the Status: Work In Progess This issue/PR is actively being worked on label May 10, 2025
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: 0

🧹 Nitpick comments (1)
maxun-core/src/browserSide/scraper.js (1)

728-750: Good addition of fallback mechanism for nth-child selectors.

The new tryFallbackSelector function is a nice enhancement that improves the robustness of element selection when the exact nth-child selectors don't match. This is especially useful for handling dynamic content where the DOM structure might change.

A few minor suggestions:

function tryFallbackSelector(rootElement, originalSelector) {
    let element = queryElement(rootElement, originalSelector);
    
    if (!element && originalSelector.includes('nth-child')) {
-       const match = originalSelector.match(/nth-child\((\d+)\)/);
-       if (match) {
-       const position = parseInt(match[1], 10);
+       const match = originalSelector.match(/(?:\:)?nth-child\((\d+)\)/);
+       if (match && match[1]) {
+           const position = parseInt(match[1], 10);
        
        for (let i = position - 1; i >= 1; i--) {
            const fallbackSelector = originalSelector.replace(/nth-child\(\d+\)/, `nth-child(${i})`);
            element = queryElement(rootElement, fallbackSelector);
            if (element) break;
        }
        
        if (!element) {
-           const baseSelector = originalSelector.replace(/\:nth-child\(\d+\)/, '');
+           const baseSelector = originalSelector.replace(/(?:\:)?nth-child\(\d+\)/, '');
            element = queryElement(rootElement, baseSelector);
        }
        }
    }
    
    return element;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b9893f and d608556.

📒 Files selected for processing (1)
  • maxun-core/src/browserSide/scraper.js (2 hunks)
🔇 Additional comments (1)
maxun-core/src/browserSide/scraper.js (1)

929-929: Good implementation of the fallback selector mechanism.

Replacing direct element querying with the fallback mechanism provides more robust element selection, especially when dealing with dynamic content where exact nth-child positions might not be reliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Ext Issues/PRs related to core extraction Status: Work In Progess This issue/PR is actively being worked on Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants