feat: Add selector parameter to scope DOM snapshots#42
feat: Add selector parameter to scope DOM snapshots#42imqqmi wants to merge 3 commits intofreema:mainfrom
Conversation
- Always traverse children even when parent element is filtered out - Relevant descendants now bubble up through non-relevant wrapper divs - Text content check uses direct text only (not all descendant text) - Add hasInteractiveDescendant() to include containers with interactive children - Add includeAll option to bypass relevance filtering entirely Fixes issue where wrapper divs with no id/class and long descendant text were filtered out along with all their children, resulting in nearly empty snapshots for SPA frameworks.
Allows scoping snapshots to a specific element using CSS selectors:
take_snapshot({ selector: 'main' })
take_snapshot({ selector: '#app table tbody' })
take_snapshot({ selector: '.content-area' })
Benefits:
- Skip irrelevant nav/header/footer when focusing on main content
- Deeper traversal into target area without hitting node limits
- More efficient token usage for large pages
- Better iterative exploration (overview first, then zoom in)
Returns clear error if selector doesn't match any element.
freema
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The core changes are solid — the tree walker fix for SPA frameworks and the selector parameter are both useful.
Before merging, a few things need attention:
- Drop
package-lock.json— it's based on0.5.2/0.6.0butmainis at0.7.1 - Rebase on current
main - Remove unrelated
.gitignorechanges (agents/,opencode.json) - Tests would be appreciated — significant refactor of
treeWalker.ts
Happy to cherry-pick the core logic myself if you don't have time for the cleanup. Let me know!
|
Yes, please, cherry-pick, I'm not able to do it myself. I'll test it when I'm doing some front-end stuff. |
|
Hey @imqqmi, thanks for the contribution and for the inspiration! 🙏 We actually implemented the
I've also added comprehensive unit tests for the injected browser scripts covering all of these features:
Since the features are already shipped and tested, I'm going to close this PR. Thanks again for taking the time to put this together! |
I'll provide this as is, I don't have too much free time to re-merge this. You're free to reject it of course.