Skip to content

Conversation

@RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented Apr 23, 2025

What this PR does?
Fixes the issue of links not being scraped at certain sites.

Closes #548

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of URL extraction for elements with href attributes, especially when the element is not a direct link, ensuring more reliable link detection in complex page structures.
  • Chores

    • Removed internal logging of browser console messages to streamline performance and reduce unnecessary console output.

@coderabbitai
Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

This change updates the extractValue function in maxun-core/src/browserSide/scraper.js to enhance the extraction of href attributes, particularly when the element is not an anchor (<a>). The new logic attempts to retrieve the href from a parent <a> element if the current element is not an anchor, improving URL extraction accuracy. Additionally, in server/src/workflow-management/selector.ts, a Playwright page event listener that logged browser console messages has been removed, with no impact on exported functions.

Changes

File(s) Change Summary
maxun-core/src/browserSide/scraper.js Updated extractValue to improve href extraction by checking parent <a> elements for non-anchor elements.
server/src/workflow-management/selector.ts Removed Playwright page.on('console', ...) listener that logged browser console messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Scraper
    participant DOM

    User->>Scraper: Request element value extraction
    Scraper->>DOM: Inspect element attributes
    alt Attribute is 'href' and element is not <a>
        Scraper->>DOM: Find parent <a> element
        alt Parent <a> exists
            Scraper->>DOM: Get href from parent <a>
            Scraper->>User: Return absolute URL
        else No parent <a>
            Scraper->>User: Return attribute or data attribute value
        end
    else Other attributes or cases
        Scraper->>DOM: Extract as per previous logic
        Scraper->>User: Return value
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly scrape links (hrefs) on elements, including cases where the link is not directly on an anchor tag (#548)

Possibly related PRs

Suggested labels

Type: Bug

Suggested reviewers

  • amhsirak

Poem

A clever bunny with code so neat,
Hopped through the DOM on nimble feet.
Found hidden links where once were none,
Now scraping is properly done!
Console logs have hopped away—
All in a bug-fixing springtime day. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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.

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)

528-529: Consider adding more fallback options for baseURL.

While using element.ownerDocument?.location?.href || window.location.origin works in most cases, some complex DOM structures might benefit from additional fallbacks.

-const baseURL = element.ownerDocument?.location?.href || window.location.origin;
+const baseURL = element.ownerDocument?.location?.href || 
+                element.ownerDocument?.baseURI || 
+                document.baseURI || 
+                window.location.origin;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ca306f and 8ef5348.

📒 Files selected for processing (2)
  • maxun-core/src/browserSide/scraper.js (1 hunks)
  • server/src/workflow-management/selector.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • server/src/workflow-management/selector.ts
🔇 Additional comments (2)
maxun-core/src/browserSide/scraper.js (2)

544-556: Good enhancement for href extraction in non-anchor elements!

This new functionality improves URL extraction accuracy by checking for parent <a> elements when the current element isn't an anchor. This is particularly useful for situations where clickable elements (like images, buttons, or spans) are nested inside anchor tags - a common pattern in modern web development.


526-581: The overall implementation of extractValue is robust and well structured.

The function handles various cases thoroughly:

  1. Checks for shadow root content
  2. Processes innerText and innerHTML attributes
  3. Special handling for src/href attributes including parent element checking
  4. Fallback to data-attributes and background images
  5. Proper URL resolution using the context-aware base URL

The try-catch blocks for URL construction (lines 549-553 and 573-577) provide good error handling for malformed URLs.

@amhsirak amhsirak merged commit 36213f8 into develop Apr 23, 2025
1 check passed
@amhsirak amhsirak added Type: Bug Something isn't working Scope: Ext Issues/PRs related to core extraction labels Apr 28, 2025
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 Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Link not being scraped

3 participants