feat(dom): add Playwright selector support, remove nodeId caching#169
Open
sfc-gh-mochen wants to merge 5 commits intoszymdzum:mainfrom
Open
feat(dom): add Playwright selector support, remove nodeId caching#169sfc-gh-mochen wants to merge 5 commits intoszymdzum:mainfrom
sfc-gh-mochen wants to merge 5 commits intoszymdzum:mainfrom
Conversation
- Remove session.json file write on stop - Remove offline session fallback from network commands - Delete unused output.ts module - Update skill to discourage premature stop calls - Remove 'save output' references from UI messages - Demote 'bdg stop' in command listings (show peek/tail first) - Update golden workflow test to use peek instead of session.json - Users should use bdg peek to inspect telemetry data
# Conflicts: # package-lock.json
Add Playwright-style pseudo-selectors:
- :has-text("text") - element contains text (case-insensitive)
- :text("text") - smallest element with exact text
- :text-is("text") - exact text match (case-sensitive)
- :visible - element is visible
Remove nodeId caching layer:
- Delete DomElementResolver and QueryCacheManager
- Remove index-based operations (bdg dom click 0)
- Always use selectors with optional --index flag
Bug fixes:
- Fix "Object reference chain is too long" in bdg dom eval by handling
non-serializable DOM elements gracefully
- Fix script execution errors by embedding QUERY_ELEMENTS_HELPER inside
each IIFE instead of concatenating before it
- Update "Next steps" to show --index when multiple matches found
- Add Playwright Selectors section with :has-text, :text, :text-is, :visible - Explain why Playwright selectors replace 2-step query+index workflow - Update Form Interaction to show selector-based approach with --index - Document that dom eval now handles DOM elements gracefully - Remove references to index-based operations (bdg dom fill 0) - Add 'Click Button by Text' pattern example
Owner
|
Hey @sfc-gh-mochen, it looks like PR #200 is a superset of this one (includes Playwright selectors + nodeId removal plus additional features). Should we close this in favor of #200? |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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