Files
BrowserOS/apps/server/tests
Nikhil ae2c216321 feat: add get_dom and search_dom tools (#398)
* feat: add get_dom and search_dom tools for HTML DOM inspection

Add two new observation tools:
- get_dom: Returns raw HTML of a page or scoped element via CSS selector
- search_dom: Fuzzy searches DOM elements by text, attributes, IDs, and
  class names using Fuse.js with extended search syntax support

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: use CDP DOM protocol instead of injected scripts for DOM tools

Replace Runtime.evaluate-based approach with native CDP DOM methods:
- get_dom uses DOM.getDocument + DOM.querySelector + DOM.getOuterHTML
- search_dom uses DOM.performSearch + DOM.getSearchResults + DOM.describeNode
- Remove fuse.js dependency (CDP performSearch handles text/CSS/XPath natively)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add comprehensive tests for get_dom and search_dom tools

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: resolve text nodes to parent elements in searchDom

CDP performSearch returns text nodes (nodeType 3) for plain text queries.
describeNode does not populate parentId, so use resolveNode + callFunctionOn
to get parentElement, then requestNode to obtain the parent's nodeId.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add limit bounds validation and searchId leak prevention

- Add .int().min(1).max(200) to search_dom limit parameter
- Wrap searchDom result processing in try/finally to ensure
  discardSearchResults is always called

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 11:35:09 -08:00
..
2026-01-19 16:58:22 -08:00