Skip to content

Commit 9d14981

Browse files
committed
fix(desktop-browser): type into a top-page field that a non-modal overlay covers
1 parent adca744 commit 9d14981

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎apps/desktop/src/main/browser-agent/driver.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,6 +4080,11 @@ async function executeToolInner(
40804080
},
40814081
}
40824082
const notes: string[] = []
4083+
if (typeof initialSurface.coveredBy === 'string') {
4084+
notes.push(
4085+
`The field is covered by ${initialSurface.coveredBy}, so the text went in through keyboard focus.`
4086+
)
4087+
}
40834088
if (submitNote) notes.push(submitNote)
40844089
if (!combinedObservation.effectObserved) {
40854090
notes.push(

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ describe('combobox typing surfaces', () => {
334334
expect(input.value).toBe('Mondu')
335335
})
336336

337-
it('refuses mixed or unrelated blockers instead of treating them as suggestions', () => {
338-
const { option } = composeField()
337+
it('does not treat mixed or unrelated blockers as suggestions, and types through keyboard focus', () => {
338+
const { input, option } = composeField()
339339
const overlay = visible(document.createElement('div'))
340340
overlay.setAttribute('aria-label', 'Unrelated overlay')
341341
document.body.append(overlay)
@@ -344,11 +344,38 @@ describe('combobox typing surfaces', () => {
344344
value: (x: number) => (x > 70 ? overlay : option),
345345
})
346346

347-
expect(focusElementForTyping(0)).toEqual({
348-
error: 'obstructed',
349-
blocker: 'Mondu',
350-
blockerControls: [],
347+
expect(focusElementForTyping(0)).toMatchObject({
348+
focused: true,
349+
coveredBy: 'Mondu',
350+
coveredByRelatedPopup: false,
351351
})
352+
expect(document.activeElement).toBe(input)
353+
})
354+
355+
it('types into a top-page field a promo card covers, naming the cover', () => {
356+
document.body.innerHTML = '<input type="search" aria-label="Search" /><div>Shop for your home</div>'
357+
const input = visible(document.querySelector('input') as HTMLInputElement)
358+
const card = visible(document.querySelector('div') as HTMLDivElement)
359+
register(input)
360+
Object.defineProperty(document, 'elementFromPoint', { configurable: true, value: () => card })
361+
362+
expect(focusElementForTyping(0)).toMatchObject({ focused: true, coveredBy: 'Shop for your home' })
363+
expect(typeIntoElement(0, 'cooking pot', false)).toMatchObject({ dispatched: true })
364+
expect(input.value).toBe('cooking pot')
365+
})
366+
367+
it('still refuses a covered field inside a frame', () => {
368+
const frame = document.createElement('iframe')
369+
document.body.append(frame)
370+
const inner = frame.contentDocument as Document
371+
inner.body.innerHTML = '<input type="text" /><div>Cover</div>'
372+
const field = visible(inner.querySelector('input') as HTMLInputElement)
373+
const cover = visible(inner.querySelector('div') as HTMLDivElement)
374+
field.scrollIntoView = () => {}
375+
register(field)
376+
Object.defineProperty(inner, 'elementFromPoint', { configurable: true, value: () => cover })
377+
378+
expect(focusElementForTyping(0)).toMatchObject({ error: 'obstructed', blocker: 'Cover' })
352379
})
353380

354381
it('refuses ambiguous composite fields and descendant passwords', () => {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,18 @@ export function focusElementForTyping(id: number, moveFocus = true): unknown {
19111911
coveredByRelatedPopup = true
19121912
}
19131913
}
1914+
// Typing reaches a focused top-page field through the keyboard, never the
1915+
// pointer, so an overlay over it (a promo card, a sticky banner) does not
1916+
// stop the text, as Playwright's fill does not hit-test either. Modal
1917+
// dialogs still refuse: their background is aria-hidden or inert, which the
1918+
// visibility and focus checks above reject. Framed fields keep the strict
1919+
// check because the driver maps their point through the parent page.
1920+
const topPageField = view === window && window.top === window
1921+
let coveredBy: string | undefined
1922+
if (!chosenPoint && topPageField && blockedPoints.length > 0) {
1923+
chosenPoint = { x: blockedPoints[0].x, y: blockedPoints[0].y }
1924+
coveredBy = blockerLabel(firstBlocker)
1925+
}
19141926
if (!chosenPoint) {
19151927
return {
19161928
error: 'obstructed',
@@ -1921,6 +1933,7 @@ export function focusElementForTyping(id: number, moveFocus = true): unknown {
19211933

19221934
return {
19231935
focused: true,
1936+
...(coveredBy ? { coveredBy } : {}),
19241937
kind:
19251938
editableTag === 'INPUT'
19261939
? 'input'

0 commit comments

Comments
 (0)