Skip to content

feat: better DOM parsing and highlighting #488

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

Merged
merged 4 commits into from
Mar 20, 2025
Merged

feat: better DOM parsing and highlighting #488

merged 4 commits into from
Mar 20, 2025

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented Mar 19, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined element detection to improve accuracy in selecting interactive components, ensuring more reliable behavior in complex visual layouts. Enhanced logic for determining the deepest element at specified coordinates, allowing for multiple elements to be considered. Removed unnecessary parent element traversal logic for simplification.

@RohitR311 RohitR311 added Type: Bug Something isn't working Type: Enhancement Improvements to existing features labels Mar 19, 2025
@RohitR311 RohitR311 requested a review from amhsirak March 19, 2025 20:13
Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request refactors the getElementInformation, getRect, getSelectors, and getNonUniqueSelectors functions within the selector module. It replaces document.elementFromPoint with document.elementsFromPoint, allowing multiple elements to be returned. A new helper function, findDeepestElement, is introduced to identify the deepest DOM element at specified coordinates. The logic for handling shadow DOM and frames has been updated to utilize the new deepest element, while legacy parent traversal code has been removed for simplification.

Changes

File(s) Change Summary
server/.../selector.ts Refactored getElementInformation, getRect, getSelectors, and getNonUniqueSelectors functions to use document.elementsFromPoint with a new helper findDeepestElement for accurate deep element selection. Updated shadow DOM and frame handling, and removed legacy parent traversal code.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Caller
    participant Selector as getElementInformation
    participant DOM as document.elementsFromPoint
    participant Finder as findDeepestElement
    Client->>Selector: Call getElementInformation(x, y)
    Selector->>DOM: Invoke document.elementsFromPoint(x, y)
    DOM-->>Selector: Return array of elements
    Selector->>Finder: Call findDeepestElement(elements)
    Finder-->>Selector: Return deepest element
    Selector->>Selector: Process shadow DOM/frames
    Selector-->>Client: Return element information and rect
Loading

Poem

I'm a hopping bunny on the prowl,
Refactoring code with a joyful howl.
Deep in the DOM, I find the key,
Shadows and frames now sing with glee.
With every line, I leap with delight,
Celebrating our code all day and night!
🐇💻


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fe67193 and 7303859.

📒 Files selected for processing (1)
  • server/src/workflow-management/selector.ts (40 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 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 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 (7)
server/src/workflow-management/selector.ts (7)

30-55: Consider refactoring repeated logic into a shared helper.

The findDeepestElement function is duplicated in multiple places. Extracting it into a shared function in a common utility file or module could simplify maintenance, reduce code duplication, and unify behavior across usage sites.


310-315: Repeated pattern noted.

This block mirrors the earlier code for retrieving elements. Consider extracting a utility to handle elementsFromPoint and the subsequent checks.


316-340: Duplicate findDeepestElement logic.

Again, consider consolidating shared logic into a reusable function to reduce repetition and potential inconsistencies.


604-605: Improves multi-element detection.

Similar duplication; consider moving repeated logic to a shared utility.


607-634: Recurrent findDeepestElement logic.

Suggest factoring out the shared routines given the repeated code block.


828-829: Repeated multi-element approach.

Again, worthwhile to unify this logic to minimize duplication.


831-858: Same findDeepestElement block repeated.

Refactor into a single, well-tested helper for ease of updates.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f3a769 and a5f8f9d.

📒 Files selected for processing (1)
  • server/src/workflow-management/selector.ts (20 hunks)
🔇 Additional comments (21)
server/src/workflow-management/selector.ts (21)

27-29: Good enhancement using document.elementsFromPoint.

This allows retrieving all elements at the specified coordinates, providing more accurate depth determination compared to document.elementFromPoint.


59-60: Looks good.

The check and immediate return for null ensures safe upstream usage.


83-83: No changes needed here.

Variable assignment is straightforward and poses no issues.


93-94: Correct approach to handle iFrame detection.

Using deepestElement.tagName === 'IFRAME' helps correct iFrame handling for further nested logic.


124-124: Frame detection is still valid although frames are legacy.

The conditional logic checks for frames or framesets, which remain relevant in some legacy contexts.


127-128: Properly collecting frame elements.

This ensures frames are queued for further processing.


343-343: All good.

Assigning the deepest element to a local variable for further references is clear and concise.


366-366: No issues with this assignment.

Simple variable assignment—no concerns.


376-377: Consistent iFrame check.

This block aligns with the approach used in other segments for iFrame handling.


410-411: Frames are handled consistently.

Pushing the frame to the array ensures further traversal if needed.


461-461: Shadow DOM traversal is properly invoked.

Allows further refining the deepest element within shadow roots.


636-637: Function call and null check look good.

This ensures safe handling of cases with no matching elements.


660-660: No further suggestions.

Simple, harmless variable assignment.


670-671: Proper iFrame logic again.

Continuing the consistent iFrame processing approach.


704-705: Frame detection remains consistent.

Reuses the same patterns for frames.


755-755: Shadow DOM traversal is properly updated.

Ensures deepest element is continually refreshed.


860-861: Straightforward usage.

No issues; the flow remains consistent.


884-884: No changes needed.

Simple local assignment; safe to ignore.


894-895: Exact iFrame check repeated.

Continues the established pattern for iFrame depth checks.


928-929: Consistent frame detection again.

Maintaining parity with other frame checks.


979-979: Shadow DOM re-traversal.

Implementation remains consistent across repeated patterns.

@amhsirak amhsirak added Scope: Ext Issues/PRs related to core extraction and removed Type: Bug Something isn't working labels Mar 19, 2025
@RohitR311
Copy link
Collaborator Author

@amhsirak Review

Copy link
Member

@amhsirak amhsirak left a comment

Choose a reason for hiding this comment

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

@RohitR311 perfectooo!

@amhsirak amhsirak merged commit e4da661 into develop Mar 20, 2025
1 check passed
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: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants