-
Notifications
You must be signed in to change notification settings - Fork 992
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
base: develop
Are you sure you want to change the base?
Conversation
""" WalkthroughThe changes introduce an explicit 2-second wait after pagination navigation in the Changes
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
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
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
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 exactnth-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
📒 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.
What this PR does?
Summary by CodeRabbit