Skip to content

Comments

fix(browser): inject data-fgp-ref attributes during ARIA snapshot#3

Merged
wolfiesch merged 2 commits intofast-gateway-protocol:masterfrom
twick00:fix/aria-ref-injection
Feb 15, 2026
Merged

fix(browser): inject data-fgp-ref attributes during ARIA snapshot#3
wolfiesch merged 2 commits intofast-gateway-protocol:masterfrom
twick00:fix/aria-ref-injection

Conversation

@twick00
Copy link
Contributor

@twick00 twick00 commented Feb 14, 2026

Description

Fix @eN element refs from browser.snapshot so they work with interaction methods (browser.click, browser.fill, etc.). Previously, snapshot extraction assigned @eN labels but never injected the corresponding data-fgp-ref attributes onto DOM elements, so resolve_selector("@e5") could never find them.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (describe):

Related Issues

Element ref resolution (@eN selectors) was non-functional.

What Changed

Adds data-fgp-ref attribute injection during ARIA tree extraction on both paths:

  • CDP path: Resolves BackendNodeIdNodeId via DOM.describeNode, then sets data-fgp-ref via DOM.setAttributeValue
  • DOM fallback path: Injects setAttribute("data-fgp-ref", "eN") in the same JS loop that discovers interactive elements

Old data-fgp-ref attributes are cleared at the start of each snapshot to prevent stale refs from previous extractions.

Testing

  • Tests pass locally (25 unit + 3 integration tests)
  • Added new tests for changes
  • Red/green verified: reverted the fix, confirmed tests fail (snapshot returns @e1, @e2 but 0 refs resolve to DOM elements), restored the fix, confirmed tests pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed the code
  • Commented complex logic
  • Updated documentation if needed
  • No breaking changes (or documented them)

…raction

The @en element refs returned by browser.snapshot were not usable by
interaction methods (click, fill, etc.) because nothing injected the
corresponding data-fgp-ref attributes onto DOM elements.

This adds attribute injection on both extraction paths:

- CDP path: resolves BackendNodeId -> NodeId via DOM.describeNode, then
  sets data-fgp-ref via DOM.setAttributeValue
- DOM fallback path: injects setAttribute('data-fgp-ref', 'eN') in the
  same JS loop that discovers interactive elements

Old data-fgp-ref attributes are cleared at the start of each snapshot
to prevent stale refs.
Adds two Chrome-dependent tests (run with `cargo test -- --ignored`):

- snapshot_refs_are_findable: verifies that @en refs from a snapshot
  resolve to actual DOM elements via data-fgp-ref attributes
- snapshot_refs_refresh_on_second_call: verifies that a second snapshot
  re-injects valid refs that still resolve correctly
@twick00 twick00 force-pushed the fix/aria-ref-injection branch from 2ceae32 to c29999c Compare February 15, 2026 00:06
@wolfiesch wolfiesch merged commit a639e36 into fast-gateway-protocol:master Feb 15, 2026
0 of 3 checks passed
wolfiesch added a commit that referenced this pull request Feb 16, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@twick00 twick00 deleted the fix/aria-ref-injection branch February 16, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants