Skip to content

Commit c59e83f

Browse files
committed
fix(desktop-browser): give text lines the identity name the resolver recomputes
1 parent eafb623 commit c59e83f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎apps/desktop/src/main/browser-agent/page-functions.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,23 @@ describe('collectSnapshot', () => {
683683
expect(clickElement(ref)).toMatchObject({ dispatched: true })
684684
})
685685

686+
it('acts on a text line whose accessible name differs from its rendered text', () => {
687+
document.body.innerHTML = '<p><span aria-label="Details">i</span></p>'
688+
visible(document.querySelector('span') as HTMLSpanElement)
689+
const ref = refFor(outlineOf(collectSnapshot()), 'i')
690+
691+
expect(clickElement(ref)).toMatchObject({ dispatched: true })
692+
})
693+
694+
it('acts on a text line longer than the identity name budget', () => {
695+
const text = 'Terms of service '.repeat(10).trim()
696+
document.body.innerHTML = `<p>${text}</p>`
697+
visible(document.querySelector('p') as HTMLParagraphElement)
698+
const ref = refFor(outlineOf(collectSnapshot()), text.slice(0, 160))
699+
700+
expect(clickElement(ref)).toMatchObject({ dispatched: true })
701+
})
702+
686703
it('invalidates a connected ref whose name changed to a longer, different word', () => {
687704
document.body.innerHTML = '<div role="listitem">Item 1</div>'
688705
const row = visible(document.querySelector('[role="listitem"]') as HTMLDivElement)

‎apps/desktop/src/main/browser-agent/page-functions.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,9 @@ export function collectSnapshot(
691691
160
692692
)
693693
if (!text) return
694-
const id = registerElement(el, roleFor(el), text)
694+
// Identity uses the name the resolver recomputes, not the displayed text,
695+
// which differs for aria-labelled leaves and past the name's length cap.
696+
const id = registerElement(el, roleFor(el), nameFor(el))
695697
textLineCount++
696698
const marker = isNew(el) ? ' new' : ''
697699
const lineIndex = lines.length

0 commit comments

Comments
 (0)