feat(dom): add Playwright selector support, remove nodeId caching #169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
AI agents naturally try to use Playwright-style selectors because they're expressive and precise:
bdg dom click 'button:text("Submit")'Problem 1: This fails because bdg only supported standard CSS selectors.
AI agents then fall back to
bdg dom eval:Problem 2: This fails with "Object reference chain is too long" because DOM elements can't be serialized.
Problem 3: The previous 2-step workflow was clunky:
This required maintaining a nodeId cache (QueryCacheManager, DomElementResolver) that could go stale.
Solution
With Playwright selectors, one precise selector replaces the 2-step workflow:
Changes
New Playwright Selectors
Removed NodeId Caching
DomElementResolver.tsandQueryCacheManager.tsbdg dom click 0)--index Nflag when selector matches multiple:bdg dom click "button" --index 0Bug Fixes
bdg dom eval "document.querySelector('button')"now returns element description instead of failing--indexexamples when multiple matches foundTest plan
bdg dom query 'button:has-text("Submit")'finds buttons with textbdg dom click 'button' --index 0clicks first matchbdg dom eval "document.querySelector('button')"returns description--index🤖 Generated with Claude Code