From 59ca1bd270937efd778f1c3630dd9c2bbd2e9215 Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 23 Nov 2026 13:08:04 +0530 Subject: [PATCH 1/3] fix(capture-kit): keep react-native dismiss-overlay off app Close buttons dismiss-overlay took any node labelled Close or a close glyph as the overlay's dismiss control and ranked semantic buttons first. An app's own [button] "Close" therefore beat LogBox's [other] "Dismiss" in the expanded inspector and suppressed the collapsed-banner fallback, so the command tapped app UI and then reported that the overlay was still detected. An app's [button] "Dismiss" beat LogBox's footer Dismiss the same way. Overlay evidence now outranks role. A Dismiss that shares its row with LogBox's Minimize or RedBox's Reload/Copy, or sits on an overlay surface, wins over one that does not. A generic close label counts only on an overlay surface: a descendant of, or fully inside, a collapsed warning banner with LogBox evidence, or a non-full-screen node whose own text names LogBox/RedBox. The collapsed-banner coordinate fallback keeps its stricter safety filter. --- .../src/react-native-overlay.test.ts | 231 ++++++++++++++++++ .../capture-kit/src/react-native-overlay.ts | 84 ++++++- .../contracts/src/react-native-overlay.ts | 2 +- 3 files changed, 306 insertions(+), 11 deletions(-) diff --git a/packages/capture-kit/src/react-native-overlay.test.ts b/packages/capture-kit/src/react-native-overlay.test.ts index f2c54e4837..0eefe0ad4e 100644 --- a/packages/capture-kit/src/react-native-overlay.test.ts +++ b/packages/capture-kit/src/react-native-overlay.test.ts @@ -347,3 +347,234 @@ describe('React Native collapsed banner with the entry-count badge', () => { expect(analyzeReactNativeOverlay(nodes).detected).toBe(false); }); }); + +/** + * Node shapes from an iOS capture where the app keeps its own `Close` buttons on screen while + * LogBox shows. A bare close label is app vocabulary, so it must not stand in for LogBox's control. + */ +describe('React Native overlay dismissal beside app close buttons', () => { + const viewport = snapshotViewportSizeFrom({ x: 0, y: 0, width: 402, height: 874 }); + const appCloseButtons = [ + node({ + index: 20, + ref: 'e20', + type: 'Button', + label: 'Close', + rect: { x: 16, y: 62, width: 44, height: 44 }, + hittable: true, + }), + node({ + index: 60, + ref: 'e60', + type: 'Button', + label: 'Close', + rect: { x: 342, y: 420, width: 44, height: 44 }, + hittable: true, + }), + ]; + const collapsedBanner = node({ + index: 70, + ref: 'e70', + type: 'Group', + label: '!, Uncaught (in promise) TypeError: Network request failed', + rect: { x: 10, y: 772, width: 382, height: 48 }, + hittable: true, + }); + + test('a collapsed banner is closed at its own affordance, not at an app Close button', () => { + const state = analyzeReactNativeOverlay([...appCloseButtons, collapsedBanner], viewport); + + expect(state.primaryAction).toMatchObject({ + action: 'close-collapsed-banner', + ref: 'e70', + point: { x: 370, y: 796 }, + }); + }); + + test('a close control inside the collapsed banner wins over app Close buttons', () => { + const state = analyzeReactNativeOverlay( + [ + ...appCloseButtons, + collapsedBanner, + node({ + index: 72, + ref: 'e72', + type: 'Other', + label: 'Close', + rect: { x: 356, y: 782, width: 28, height: 28 }, + }), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e72' }); + }); + + test('the expanded inspector Dismiss control wins over app Close buttons whatever its role', () => { + const state = analyzeReactNativeOverlay( + [ + ...appCloseButtons, + node({ + index: 80, + ref: 'e80', + type: 'StaticText', + label: 'Log 1 of 1', + rect: { x: 151, y: 62, width: 100, height: 20 }, + }), + node({ + index: 84, + ref: 'e84', + type: 'StaticText', + label: 'Call Stack', + rect: { x: 12, y: 300, width: 90, height: 24 }, + }), + node({ + index: 90, + ref: 'e90', + type: 'Other', + label: 'Dismiss', + rect: { x: 0, y: 792, width: 201, height: 48 }, + }), + node({ + index: 91, + ref: 'e91', + type: 'Other', + label: 'Minimize', + rect: { x: 201, y: 792, width: 201, height: 48 }, + }), + ], + viewport, + ); + + expect(state.detected).toBe(true); + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e90', + point: { x: 101, y: 816 }, + }); + }); + + test('the inspector footer Dismiss wins over an app toast Dismiss button', () => { + const state = analyzeReactNativeOverlay( + [ + node({ + index: 30, + ref: 'e30', + type: 'Button', + label: 'Dismiss', + rect: { x: 300, y: 120, width: 86, height: 44 }, + hittable: true, + }), + node({ + index: 84, + ref: 'e84', + type: 'StaticText', + label: 'Call Stack', + rect: { x: 12, y: 300, width: 90, height: 24 }, + }), + node({ + index: 90, + ref: 'e90', + type: 'Other', + label: 'Dismiss', + rect: { x: 0, y: 792, width: 201, height: 48 }, + }), + node({ + index: 91, + ref: 'e91', + type: 'Other', + label: 'Minimize', + rect: { x: 201, y: 792, width: 201, height: 48 }, + }), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e90' }); + }); + + test('a Close inside a key-prop warning banner is the dismiss target', () => { + // The banner is not safe to tap blind, but a close control inside it belongs to LogBox. + const state = analyzeReactNativeOverlay( + [ + ...appCloseButtons, + node({ + index: 70, + ref: 'e70', + label: 'Warning: Each child in a list should have a unique "key" prop.', + rect: { x: 0, y: 794, width: 402, height: 52 }, + hittable: true, + }), + node({ + index: 71, + ref: 'e71', + type: 'Button', + label: 'Close', + rect: { x: 356, y: 803, width: 34, height: 34 }, + hittable: true, + }), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e71' }); + }); + + test('a Close whose tree parent is the banner counts even when its frame overflows it', () => { + const state = analyzeReactNativeOverlay( + [ + ...appCloseButtons, + collapsedBanner, + node({ + index: 73, + ref: 'e73', + type: 'Button', + label: 'Close', + parentIndex: 70, + rect: { x: 380, y: 778, width: 36, height: 36 }, + }), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e73' }); + }); + + test('a full-screen container carrying overlay text does not vouch for an app Close', () => { + const state = analyzeReactNativeOverlay( + [ + node({ + index: 1, + ref: 'e1', + type: 'Other', + label: 'Runtime Error', + rect: { x: 0, y: 0, width: 402, height: 874 }, + }), + ...appCloseButtons, + ], + viewport, + ); + + expect(state.detected).toBe(true); + expect(state.primaryAction).toBe(null); + }); + + test('an inspector without a Dismiss control never falls back to an app Close button', () => { + const state = analyzeReactNativeOverlay( + [ + ...appCloseButtons, + node({ + index: 84, + ref: 'e84', + type: 'StaticText', + label: 'Call Stack', + rect: { x: 12, y: 300, width: 90, height: 24 }, + }), + ], + viewport, + ); + + expect(state.detected).toBe(true); + expect(state.primaryAction).toBe(null); + }); +}); diff --git a/packages/capture-kit/src/react-native-overlay.ts b/packages/capture-kit/src/react-native-overlay.ts index 664105e29f..4d96c3e360 100644 --- a/packages/capture-kit/src/react-native-overlay.ts +++ b/packages/capture-kit/src/react-native-overlay.ts @@ -4,7 +4,7 @@ import { type Rect, type SnapshotNode, } from '@agent-device/kernel/snapshot'; -import { rectArea } from '@agent-device/kernel/rect'; +import { rectArea, rectContains } from '@agent-device/kernel/rect'; import { isReactNativeCollapsedWarningBanner, isReactNativeCollapsedWarningCountBadgeBanner, @@ -12,6 +12,7 @@ import { isReactNativeCollapsedWarningLabel, isReactNativeOverlayDismissLabel, isReactNativeOverlayMinimizeLabel, + isFullScreenOverlayRect, } from '@agent-device/contracts/react-native-overlay'; import type { ReactNativeOverlayNode, @@ -40,6 +41,11 @@ type ReactNativeOverlayFacts = { minimizeNodes: SnapshotNode[]; collapsedNodes: SnapshotNode[]; collapsedCountBadgeNodes: SnapshotNode[]; + /** LogBox/RedBox regions a close control can belong to. */ + overlaySurfaceNodes: ReadonlySet; + /** LogBox/RedBox controls that share the footer row with their Dismiss. */ + footerControlNodes: SnapshotNode[]; + nodeByIndex: ReadonlyMap; detected: boolean; }; @@ -50,6 +56,7 @@ const REACT_NATIVE_STACK_FRAME_PATTERNS = [ /\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/, ] as const; const CLOSE_ICON_LABELS = new Set(['x', '×', '✕', '✖', '⨯']); +const REDBOX_FOOTER_CONTROL_PATTERN = /^(?:reload(?: js)?|copy)(?:\s*\([^)]*\))?$/; export function formatReactNativeOverlayWarning( nodes: SnapshotNode[], @@ -98,20 +105,36 @@ function collectReactNativeOverlayFacts( const collapsedCountBadgeNodes = collapsedNodes.filter((node) => isReactNativeCollapsedWarningCountBadgeBanner(node, surface), ); + const collapsedEvidenceNodes = collapsedNodes.filter((node) => + nodeHasMatchingLabel(node, isReactNativeCollapsedWarningEvidenceLabel), + ); return { dismissNodes, minimizeNodes, collapsedNodes, collapsedCountBadgeNodes, + overlaySurfaceNodes: new Set([ + ...[...collapsedEvidenceNodes, ...collapsedCountBadgeNodes].filter( + isReactNativeCollapsedWarningBanner, + ), + ...nodes.filter( + (node) => + !isFullScreenOverlayRect(node.rect) && + hasKnownReactNativeOverlayText(formatNodeSearchText(node).toLowerCase()), + ), + ]), + footerControlNodes: [ + ...minimizeNodes, + ...collectOverlayNodes(nodes, (label) => REDBOX_FOOTER_CONTROL_PATTERN.test(label)), + ], + nodeByIndex: new Map(nodes.map((node) => [node.index, node])), detected: isReactNativeOverlayDetected({ text, hasReactNativeStackFrame, hasOverlayControl, hasControllessRedBoxText, collapsedNodes, - collapsedEvidenceNodes: collapsedNodes.filter((node) => - nodeHasMatchingLabel(node, isReactNativeCollapsedWarningEvidenceLabel), - ), + collapsedEvidenceNodes, collapsedCountBadgeNodes, openDebuggerWarningNodes, }), @@ -134,11 +157,25 @@ function isCollapsedWarningNode( ); } +/** Apps label their own buttons Dismiss and Close too, so overlay evidence outranks role. */ function resolveSafeDismissAction( facts: ReactNativeOverlayFacts, ): ReactNativeOverlayDismissTarget | null { - const dismiss = firstControlNodeWithRect(facts.dismissNodes); - if (dismiss) return targetFromNode(dismiss, actionFromDismissNode(dismiss)); + const dismiss = selectHighestScoredNode( + facts.dismissNodes.filter((node) => + nodeHasMatchingLabel(node, isReactNativeOverlayDismissLabel), + ), + (node) => [ + booleanScore(isOnOverlaySurface(node, facts) || sharesFooterRow(node, facts)), + ...controlNodeScores(node), + ], + ); + if (dismiss) return targetFromNode(dismiss, 'dismiss'); + + const close = firstControlNodeWithRect( + facts.dismissNodes.filter((node) => isOnOverlaySurface(node, facts)), + ); + if (close) return targetFromNode(close, 'close'); const collapsed = chooseCollapsedWarningNode( facts.collapsedNodes.filter((node) => isSafeCollapsedWarningCoordinateFallback(node, facts)), @@ -287,10 +324,37 @@ function targetFromNode( }; } -function actionFromDismissNode(node: SnapshotNode): ReactNativeOverlayDismissTarget['action'] { - const label = readNodeLabel(node)?.trim().toLowerCase(); - if (label && isReactNativeOverlayDismissLabel(label)) return 'dismiss'; - return 'close'; +function isOnOverlaySurface(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { + if (hasOverlaySurfaceAncestor(node, facts)) return true; + const rect = node.rect; + if (!rect) return false; + return [...facts.overlaySurfaceNodes].some( + (surface) => surface.rect !== undefined && rectContains(surface.rect, rect), + ); +} + +function hasOverlaySurfaceAncestor(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { + const visited = new Set(); + let parentIndex = node.parentIndex; + while (typeof parentIndex === 'number' && !visited.has(parentIndex)) { + visited.add(parentIndex); + const parent = facts.nodeByIndex.get(parentIndex); + if (!parent) return false; + if (facts.overlaySurfaceNodes.has(parent)) return true; + parentIndex = parent.parentIndex; + } + return false; +} + +function sharesFooterRow(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { + const rect = node.rect; + if (!rect) return false; + return facts.footerControlNodes.some( + (control) => + control.rect !== undefined && + control.rect.y < rect.y + rect.height && + rect.y < control.rect.y + control.rect.height, + ); } function chooseCollapsedWarningNode(nodes: SnapshotNode[]): SnapshotNode | null { diff --git a/packages/contracts/src/react-native-overlay.ts b/packages/contracts/src/react-native-overlay.ts index fef8fbc318..23aa8a68d8 100644 --- a/packages/contracts/src/react-native-overlay.ts +++ b/packages/contracts/src/react-native-overlay.ts @@ -206,7 +206,7 @@ function isCloseTo(measured: number, expected: number): boolean { return Math.abs(measured - expected) <= COLLAPSED_BANNER_SIDE_INSET_TOLERANCE; } -function isFullScreenOverlayRect(rect: RawSnapshotNode['rect']): boolean { +export function isFullScreenOverlayRect(rect: RawSnapshotNode['rect']): boolean { if (!rect) return false; return rect.x <= 1 && rect.y <= 1 && rect.width >= 300 && rect.height >= 600; } From c3767afa40840c05e69a682a170d8f13101eddcd Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 23 Nov 2026 19:43:06 +0530 Subject: [PATCH 2/3] fix(capture-kit): take only the footer Dismiss of the React Native overlay Overlay evidence ranked Dismiss and Close candidates but never gated them, and the evidence itself came from app-shaped facts: any Minimize, Reload or Copy in the same row, any node whose text named LogBox, and any control inside a banner's frame although LogBox floats over app content. The only control taken is now the footer Dismiss of LogBox's inspector or of RedBox. Both footers give each control an equal column across one row, so Dismiss and its Minimize, Reload, Copy or Extra Info partners sit centered at an even spacing, and the row meets the surface edges, or stops short by at most a landscape side inset (80 dp). Without a surface, a footer needs three or more columns. The target is Dismiss's column, whether the capture lists the full tile, only its text, or a row it folded the Dismiss tile into (the iOS simulator accessibility capture labels the footer row Dismiss and nests the other tiles inside it, so the row's center is Minimize). Otherwise the collapsed banner is closed at its own affordance, except while the inspector's Dismiss and Minimize share a row, when the banner lies under the inspector. Role, hittable and area no longer rank anything, and the unused 'close' action is gone. Handler fixtures for the inspector and RedBox now carry a surface and an evenly spaced footer; the banner fixtures use a LogBox evidence label. --- .../src/react-native-overlay.test.ts | 631 ++++++++++++++---- .../capture-kit/src/react-native-overlay.ts | 238 ++++--- .../contracts/src/react-native-overlay.ts | 2 +- .../handlers/__tests__/react-native.test.ts | 135 ++-- 4 files changed, 736 insertions(+), 270 deletions(-) diff --git a/packages/capture-kit/src/react-native-overlay.test.ts b/packages/capture-kit/src/react-native-overlay.test.ts index 0eefe0ad4e..bce304453a 100644 --- a/packages/capture-kit/src/react-native-overlay.test.ts +++ b/packages/capture-kit/src/react-native-overlay.test.ts @@ -349,78 +349,100 @@ describe('React Native collapsed banner with the entry-count badge', () => { }); /** - * Node shapes from an iOS capture where the app keeps its own `Close` buttons on screen while - * LogBox shows. A bare close label is app vocabulary, so it must not stand in for LogBox's control. + * Shapes from an iOS 27 capture of React Native 0.88 with the app's own `[button] "Close"` and + * `[button] "Dismiss"` on screen, where the overlay controls are LogBox's. Tests marked synthetic + * build app layouts and Android or RedBox shapes from their layout code instead. */ -describe('React Native overlay dismissal beside app close buttons', () => { +describe('React Native overlay dismissal beside app Close and Dismiss buttons', () => { const viewport = snapshotViewportSizeFrom({ x: 0, y: 0, width: 402, height: 874 }); - const appCloseButtons = [ + const appButtons = [ node({ - index: 20, - ref: 'e20', + index: 9, + ref: 'e10', type: 'Button', label: 'Close', - rect: { x: 16, y: 62, width: 44, height: 44 }, + rect: { x: 18, y: 231, width: 73, height: 45 }, hittable: true, }), node({ - index: 60, - ref: 'e60', + index: 10, + ref: 'e11', type: 'Button', - label: 'Close', - rect: { x: 342, y: 420, width: 44, height: 44 }, + label: 'Dismiss', + rect: { x: 99, y: 231, width: 89, height: 45 }, hittable: true, }), ]; const collapsedBanner = node({ - index: 70, - ref: 'e70', - type: 'Group', - label: '!, Uncaught (in promise) TypeError: Network request failed', - rect: { x: 10, y: 772, width: 382, height: 48 }, + index: 48, + ref: 'e49', + type: 'Other', + label: '!, agent-device overlay check', + rect: { x: 10, y: 788, width: 382, height: 48 }, hittable: true, }); + const componentStackText = node({ + index: 50, + ref: 'e51', + type: 'StaticText', + label: 'Component Stack', + rect: { x: 12, y: 659, width: 378, height: 20 }, + }); + const footerTile = (index: number, label: string, x: number, extra: Partial = {}) => + node({ + index, + ref: `e${index + 1}`, + type: 'Other', + label, + rect: { x, y: 792, width: 134, height: 48 }, + hittable: false, + ...extra, + }); + /** LogBox's inspector footer as the XCTest capture lists it: three `flex: 1` tiles. */ + const inspectorFooter = [ + footerTile(59, 'Dismiss', 0), + footerTile(60, 'Minimize', 134), + footerTile(61, 'Copy', 268), + ]; - test('a collapsed banner is closed at its own affordance, not at an app Close button', () => { - const state = analyzeReactNativeOverlay([...appCloseButtons, collapsedBanner], viewport); + test('a collapsed banner is closed at its own affordance, not at an app Close or Dismiss', () => { + const state = analyzeReactNativeOverlay([...appButtons, collapsedBanner], viewport); expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', - ref: 'e70', - point: { x: 370, y: 796 }, + ref: 'e49', + point: { x: 370, y: 812 }, }); }); - test('a close control inside the collapsed banner wins over app Close buttons', () => { - const state = analyzeReactNativeOverlay( - [ - ...appCloseButtons, - collapsedBanner, - node({ - index: 72, - ref: 'e72', - type: 'Other', - label: 'Close', - rect: { x: 356, y: 782, width: 28, height: 28 }, - }), - ], - viewport, - ); - - expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e72' }); - }); - - test('the expanded inspector Dismiss control wins over app Close buttons whatever its role', () => { + test.each(['Dismiss', '×', 'Close'])( + 'synthetic: an app %s under the floating banner is not the banner close', + (label) => { + // LogBox floats over app content, so an app control can sit inside the banner's frame. + const state = analyzeReactNativeOverlay( + [ + collapsedBanner, + node({ + index: 60, + ref: 'e60', + type: 'Button', + label, + parentIndex: 1, + rect: { x: 300, y: 796, width: 80, height: 32 }, + hittable: true, + }), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); + }, + ); + + test('an app Dismiss beside inspector text alone is not a target', () => { const state = analyzeReactNativeOverlay( [ - ...appCloseButtons, - node({ - index: 80, - ref: 'e80', - type: 'StaticText', - label: 'Log 1 of 1', - rect: { x: 151, y: 62, width: 100, height: 20 }, - }), + ...appButtons, node({ index: 84, ref: 'e84', @@ -428,129 +450,299 @@ describe('React Native overlay dismissal beside app close buttons', () => { label: 'Call Stack', rect: { x: 12, y: 300, width: 90, height: 24 }, }), - node({ - index: 90, - ref: 'e90', - type: 'Other', - label: 'Dismiss', - rect: { x: 0, y: 792, width: 201, height: 48 }, - }), - node({ - index: 91, - ref: 'e91', - type: 'Other', - label: 'Minimize', - rect: { x: 201, y: 792, width: 201, height: 48 }, - }), ], viewport, ); expect(state.detected).toBe(true); + expect(state.primaryAction).toBe(null); + }); + + test('the inspector footer Dismiss wins over app buttons whatever its role', () => { + const state = analyzeReactNativeOverlay( + [...appButtons, componentStackText, ...inspectorFooter, collapsedBanner], + viewport, + ); + expect(state.primaryAction).toMatchObject({ action: 'dismiss', - ref: 'e90', - point: { x: 101, y: 816 }, + ref: 'e60', + point: { x: 67, y: 816 }, }); }); - test('the inspector footer Dismiss wins over an app toast Dismiss button', () => { + test.each([ + { direction: 'left-to-right', minimizeX: 134, copyX: 268, tapX: 67 }, + { direction: 'right-to-left', minimizeX: 134, copyX: 0, tapX: 335 }, + ])( + 'a $direction footer folded into its Dismiss row is tapped in the Dismiss column', + ({ minimizeX, copyX, tapX }) => { + // The simulator accessibility capture labels the footer row with its first tile and nests + // Minimize and Copy inside it, so the row's center would land on Minimize. Left to right is + // from the device; right to left mirrors it. + const row = { y: 792, width: 134, height: 82 }; + const state = analyzeReactNativeOverlay( + [ + ...appButtons, + componentStackText, + node({ + index: 64, + ref: 'e65', + type: 'Other', + label: 'Dismiss', + rect: { x: 0, y: 792, width: 402, height: 82 }, + hittable: true, + }), + node({ index: 65, ref: 'e66', label: 'Minimize', rect: { ...row, x: minimizeX } }), + node({ index: 66, ref: 'e67', label: 'Copy', rect: { ...row, x: copyX } }), + { ...collapsedBanner, rect: { x: 10, y: 786.67, width: 382, height: 67.33 } }, + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e65', + point: { x: tapX, y: 833 }, + }); + }, + ); + + test('synthetic: a right-to-left footer keeps its Dismiss across float32 tile edges', () => { + // A 430pt window splits into thirds that the tree reports as float32. + const tile = (index: number, label: string, x: number) => + node({ + index, + ref: `e${index}`, + label, + rect: { x, y: 850, width: 143.3333282470703, height: 48 }, + }); + const state = analyzeReactNativeOverlay( + [ + ...appButtons, + componentStackText, + tile(59, 'Copy', 0), + tile(60, 'Minimize', 143.33334350585938), + tile(61, 'Dismiss', 286.6666564941406), + ], + snapshotViewportSizeFrom({ x: 0, y: 0, width: 430, height: 932 }), + ); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e61' }); + }); + + test('synthetic: an app row with its own Reload and Dismiss is not the inspector footer', () => { const state = analyzeReactNativeOverlay( [ node({ index: 30, ref: 'e30', type: 'Button', - label: 'Dismiss', - rect: { x: 300, y: 120, width: 86, height: 44 }, + label: 'Reload', + rect: { x: 18, y: 300, width: 80, height: 44 }, hittable: true, }), node({ - index: 84, - ref: 'e84', - type: 'StaticText', - label: 'Call Stack', - rect: { x: 12, y: 300, width: 90, height: 24 }, - }), - node({ - index: 90, - ref: 'e90', - type: 'Other', + index: 31, + ref: 'e31', + type: 'Button', label: 'Dismiss', - rect: { x: 0, y: 792, width: 201, height: 48 }, + rect: { x: 106, y: 300, width: 89, height: 44 }, + hittable: true, }), + componentStackText, + ...inspectorFooter, + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e60' }); + }); + + test.each([ + { shape: 'an inset segmented pair in portrait', width: 402, height: 874, x: 66 }, + { shape: 'an alert button pair in landscape', width: 874, height: 402, x: 302 }, + ])('synthetic: $shape of flush Reload and Dismiss is not a footer', ({ width, height, x }) => { + const button = (index: number, label: string, left: number) => + node({ + index, + ref: `e${index}`, + type: 'Button', + label, + rect: { x: left, y: 300, width: 135, height: 44 }, + hittable: true, + }); + const state = analyzeReactNativeOverlay( + [button(30, 'Reload', x), button(31, 'Dismiss', x + 135), collapsedBanner], + snapshotViewportSizeFrom({ x: 0, y: 0, width, height }), + ); + + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); + }); + + test('synthetic: an app Dismiss centered on screen with no footer partners is not a footer', () => { + const state = analyzeReactNativeOverlay( + [ node({ - index: 91, - ref: 'e91', - type: 'Other', - label: 'Minimize', - rect: { x: 201, y: 792, width: 201, height: 48 }, + index: 30, + ref: 'e30', + type: 'Button', + label: 'Dismiss', + rect: { x: 151, y: 500, width: 100, height: 44 }, + hittable: true, }), + collapsedBanner, ], viewport, ); - expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e90' }); + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); }); - test('a Close inside a key-prop warning banner is the dismiss target', () => { - // The banner is not safe to tap blind, but a close control inside it belongs to LogBox. + test('synthetic: a footer row with a second Copy off its column is not read as a footer', () => { const state = analyzeReactNativeOverlay( [ - ...appCloseButtons, + componentStackText, node({ index: 70, ref: 'e70', - label: 'Warning: Each child in a list should have a unique "key" prop.', - rect: { x: 0, y: 794, width: 402, height: 52 }, - hittable: true, - }), - node({ - index: 71, - ref: 'e71', - type: 'Button', - label: 'Close', - rect: { x: 356, y: 803, width: 34, height: 34 }, - hittable: true, + label: 'Copy', + rect: { x: 300, y: 792, width: 60, height: 48 }, }), + ...inspectorFooter, ], viewport, ); - expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e71' }); + expect(state.detected).toBe(true); + expect(state.primaryAction).toBe(null); + }); + + test('without a surface, a three-column footer is still read', () => { + // macOS desktop captures publish no viewport. + const state = analyzeReactNativeOverlay([ + componentStackText, + ...inspectorFooter, + collapsedBanner, + ]); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e60', point: { x: 67 } }); }); - test('a Close whose tree parent is the banner counts even when its frame overflows it', () => { + test("synthetic: without a surface, an app's flush two-button row is not a footer", () => { + const button = (index: number, label: string, x: number) => + node({ index, ref: `e${index}`, label, rect: { x, y: 300, width: 135, height: 44 } }); + const state = analyzeReactNativeOverlay([ + button(30, 'Reload', 66), + button(31, 'Dismiss', 201), + collapsedBanner, + ]); + + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); + }); + + test('synthetic: a malformed footer row does not fall back to the banner under it', () => { const state = analyzeReactNativeOverlay( [ - ...appCloseButtons, + componentStackText, + inspectorFooter[0]!, + footerTile(60, 'Minimize', 113), + inspectorFooter[2]!, collapsedBanner, + ], + viewport, + ); + + expect(state.detected).toBe(true); + expect(state.primaryAction).toBe(null); + }); + + test('synthetic: an app Close beside a media player Minimize leaves the banner close', () => { + const state = analyzeReactNativeOverlay( + [footerTile(30, 'Minimize', 134), footerTile(31, 'Close', 0), collapsedBanner], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); + }); + + test.each([ + { shape: 'stops short of the left edge', start: 20, width: 127.33 }, + { shape: 'stops short of the right edge', start: 0, width: 127.33 }, + { shape: 'runs past the left edge', start: -20, width: 140.67 }, + ])('synthetic: a portrait footer row that $shape is not read', ({ start, width }) => { + const tiles = ['Dismiss', 'Minimize', 'Copy'].map((label, column) => + node({ + index: 59 + column, + ref: `e${60 + column}`, + label, + rect: { x: start + column * width, y: 792, width, height: 48 }, + }), + ); + const state = analyzeReactNativeOverlay( + [componentStackText, ...tiles, collapsedBanner], + viewport, + ); + + expect(state.primaryAction).toBe(null); + }); + + test('synthetic: an app Dismiss and a media player Minimize on different rows leave the banner close', () => { + const state = analyzeReactNativeOverlay( + [ + ...appButtons, node({ - index: 73, - ref: 'e73', + index: 30, + ref: 'e30', type: 'Button', - label: 'Close', - parentIndex: 70, - rect: { x: 380, y: 778, width: 36, height: 36 }, + label: 'Minimize', + rect: { x: 18, y: 400, width: 100, height: 44 }, + hittable: true, }), + collapsedBanner, ], viewport, ); - expect(state.primaryAction).toMatchObject({ action: 'close', ref: 'e73' }); + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); }); - test('a full-screen container carrying overlay text does not vouch for an app Close', () => { + test('synthetic: a Close tile beside Minimize and Copy is not the footer Dismiss', () => { + const state = analyzeReactNativeOverlay( + [componentStackText, footerTile(59, 'Close', 0), ...inspectorFooter.slice(1)], + viewport, + ); + + expect(state.primaryAction).toBe(null); + }); + + test('synthetic: an app container titled with overlay words does not vouch for its Close', () => { const state = analyzeReactNativeOverlay( [ node({ index: 1, ref: 'e1', type: 'Other', - label: 'Runtime Error', - rect: { x: 0, y: 0, width: 402, height: 874 }, + label: 'Runtime error', + rect: { x: 16, y: 300, width: 370, height: 200 }, + }), + node({ + index: 2, + ref: 'e2', + type: 'Button', + label: 'Close', + parentIndex: 1, + rect: { x: 334, y: 308, width: 44, height: 44 }, + hittable: true, + }), + node({ + index: 3, + ref: 'e3', + type: 'StaticText', + label: 'Call Stack', + parentIndex: 1, + rect: { x: 24, y: 360, width: 90, height: 24 }, }), - ...appCloseButtons, ], viewport, ); @@ -559,22 +751,221 @@ describe('React Native overlay dismissal beside app close buttons', () => { expect(state.primaryAction).toBe(null); }); - test('an inspector without a Dismiss control never falls back to an app Close button', () => { + test('synthetic: an app "Dismiss (Esc)" button beside a banner is not RedBox', () => { const state = analyzeReactNativeOverlay( [ - ...appCloseButtons, node({ - index: 84, - ref: 'e84', - type: 'StaticText', - label: 'Call Stack', - rect: { x: 12, y: 300, width: 90, height: 24 }, + index: 30, + ref: 'e30', + type: 'Button', + label: 'Dismiss (Esc)', + rect: { x: 18, y: 400, width: 120, height: 44 }, + hittable: true, }), + collapsedBanner, ], viewport, ); - expect(state.detected).toBe(true); - expect(state.primaryAction).toBe(null); + expect(state.primaryAction).toMatchObject({ action: 'close-collapsed-banner', ref: 'e49' }); + }); + + test("synthetic: RedBox's footer Dismiss wins over an app Dismiss button", () => { + // RCTRedBoxController: four buttons in a fill-equally stack view across the window. + const redBoxButton = (index: number, label: string, x: number) => + node({ + index, + ref: `e${index}`, + type: 'Button', + label, + rect: { x, y: 792, width: 100.5, height: 48 }, + hittable: true, + }); + const state = analyzeReactNativeOverlay( + [ + ...appButtons, + node({ index: 1, ref: 'e1', label: 'App.tsx:42:7' }), + redBoxButton(40, 'Dismiss\n(ESC)', 0), + redBoxButton(41, 'Reload\n(⌘R)', 100.5), + redBoxButton(42, 'Copy\n(⌥⌘C)', 201), + redBoxButton(43, 'Extra Info\n(⌘E)', 301.5), + ], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e40', + point: { x: 50, y: 816 }, + }); + }); + + /** + * Landscape shapes from the same device. Each footer button sits in its own SafeAreaView, so the + * outer tiles lose the 62 pt side insets: the XCTest capture lists tiles at 62, 291.33 and 582.67, + * and the simulator accessibility capture folds them into a full-width row labelled Dismiss. + */ + describe('iPhone landscape inspector footer', () => { + const landscape = snapshotViewportSizeFrom({ x: 0, y: 0, width: 874, height: 402 }); + const tile = (index: number, label: string, x: number, width: number, height = 48) => + node({ index, ref: `e${index + 1}`, label, rect: { x, y: 334, width, height } }); + + test('the inset tiles are read as the footer', () => { + const state = analyzeReactNativeOverlay( + [ + ...appButtons, + componentStackText, + tile(15, 'Dismiss', 62, 229.33), + tile(16, 'Minimize', 291.33, 291.33), + tile(17, 'Copy', 582.67, 229.33), + ], + landscape, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e16', + point: { x: 177, y: 358 }, + }); + }); + + test('a folded row is tapped in its Dismiss column', () => { + const state = analyzeReactNativeOverlay( + [ + ...appButtons, + componentStackText, + tile(41, 'Dismiss', 0, 874, 68), + tile(42, 'Minimize', 291.33, 291.33, 68), + tile(43, 'Copy', 582.67, 291.33, 68), + ], + landscape, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e42', + point: { x: 146, y: 368 }, + }); + }); + + test('synthetic: a row inset past the landscape side inset is not a footer', () => { + const state = analyzeReactNativeOverlay( + [ + componentStackText, + tile(15, 'Dismiss', 132, 180), + tile(16, 'Minimize', 312, 180), + tile(17, 'Copy', 492, 180), + ], + landscape, + ); + + expect(state.primaryAction).toBe(null); + }); + }); + + /** + * Android publishes physical pixels. The footer's Pressable carries its text as content + * description, but a capture may list only the centered TextViews, or both. + */ + describe('synthetic Android inspector footer', () => { + const surface = { width: 1080, height: 2400, rectUnitsPerDp: 2.625 }; + const text = (index: number, label: string, centerX: number, width: number) => + node({ + index, + ref: `e${index}`, + type: 'android.widget.TextView', + label, + rect: { x: centerX - width / 2, y: 2213, width, height: 53 }, + }); + const footerTexts = [ + // Text sits a few pixels off its column's center, within 2 dp at this density. + text(70, 'Dismiss', 183, 160), + text(71, 'Minimize', 543, 182), + text(72, 'Copy', 897, 102), + ]; + const footerTiles = ['Dismiss', 'Minimize', 'Copy'].map((label, column) => + node({ + index: 80 + column, + ref: `e${80 + column}`, + type: 'android.view.ViewGroup', + label, + rect: { x: column * 360, y: 2176, width: 360, height: 126 }, + hittable: true, + }), + ); + const banner = node({ + index: 90, + ref: 'e90', + label: '!, agent-device overlay check', + rect: { x: 26, y: 2148, width: 1028, height: 126 }, + hittable: true, + }); + const appDismiss = node({ + index: 20, + ref: 'e20', + type: 'android.widget.Button', + label: 'Dismiss', + rect: { x: 260, y: 600, width: 230, height: 118 }, + hittable: true, + }); + + test('only the footer text is listed: the Dismiss text is tapped, not the banner below', () => { + const state = analyzeReactNativeOverlay( + [appDismiss, componentStackText, ...footerTexts, banner], + surface, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e70', + point: { x: 183, y: 2240 }, + }); + }); + + test('tiles and their text are both listed: Dismiss is still one column', () => { + const state = analyzeReactNativeOverlay( + [ + appDismiss, + componentStackText, + node({ index: 99, ref: 'e99', label: 'Dismiss' }), + ...footerTiles, + ...footerTexts, + node({ index: 98, ref: 'e98', label: 'Minimize' }), + banner, + ], + surface, + ); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', point: { x: 180 } }); + }); + + test('in landscape, a footer inset by the cutout and the navigation bar is still read', () => { + // LogBoxDialog margins the root by the cutout (110 px) and the side navigation bar (126 px). + const columnWidth = (2400 - 110 - 126) / 3; + const tile = (index: number, label: string, column: number) => + node({ + index, + ref: `e${index}`, + label, + rect: { x: 110 + column * columnWidth, y: 940, width: columnWidth, height: 126 }, + hittable: true, + }); + const state = analyzeReactNativeOverlay( + [ + appDismiss, + componentStackText, + tile(80, 'Dismiss', 0), + tile(81, 'Minimize', 1), + tile(82, 'Copy', 2), + ], + { width: 2400, height: 1080, rectUnitsPerDp: 2.625 }, + ); + + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e80', + point: { x: 471 }, + }); + }); }); }); diff --git a/packages/capture-kit/src/react-native-overlay.ts b/packages/capture-kit/src/react-native-overlay.ts index 4d96c3e360..01d021e937 100644 --- a/packages/capture-kit/src/react-native-overlay.ts +++ b/packages/capture-kit/src/react-native-overlay.ts @@ -4,7 +4,6 @@ import { type Rect, type SnapshotNode, } from '@agent-device/kernel/snapshot'; -import { rectArea, rectContains } from '@agent-device/kernel/rect'; import { isReactNativeCollapsedWarningBanner, isReactNativeCollapsedWarningCountBadgeBanner, @@ -12,7 +11,6 @@ import { isReactNativeCollapsedWarningLabel, isReactNativeOverlayDismissLabel, isReactNativeOverlayMinimizeLabel, - isFullScreenOverlayRect, } from '@agent-device/contracts/react-native-overlay'; import type { ReactNativeOverlayNode, @@ -28,7 +26,7 @@ export type ReactNativeOverlayState = { }; export type ReactNativeOverlayDismissTarget = { - action: 'close' | 'dismiss' | 'close-collapsed-banner'; + action: 'dismiss' | 'close-collapsed-banner'; point: Point; rect?: Rect; ref?: string; @@ -41,11 +39,9 @@ type ReactNativeOverlayFacts = { minimizeNodes: SnapshotNode[]; collapsedNodes: SnapshotNode[]; collapsedCountBadgeNodes: SnapshotNode[]; - /** LogBox/RedBox regions a close control can belong to. */ - overlaySurfaceNodes: ReadonlySet; - /** LogBox/RedBox controls that share the footer row with their Dismiss. */ - footerControlNodes: SnapshotNode[]; - nodeByIndex: ReadonlyMap; + /** Minimize, Reload, Copy and Extra Info: the controls that share a footer with Dismiss. */ + footerPartnerNodes: SnapshotNode[]; + surface: ReactNativeOverlaySurface | undefined; detected: boolean; }; @@ -56,7 +52,21 @@ const REACT_NATIVE_STACK_FRAME_PATTERNS = [ /\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/, ] as const; const CLOSE_ICON_LABELS = new Set(['x', '×', '✕', '✖', '⨯']); -const REDBOX_FOOTER_CONTROL_PATTERN = /^(?:reload(?: js)?|copy)(?:\s*\([^)]*\))?$/; +const FOOTER_PARTNER_PATTERN = /^(?:minimi[sz]e|reload(?: js)?|copy|extra info)(?:\s*\([^)]*\))?$/; +/** Text centered in its column can sit a rounding step off the column's center. */ +const FOOTER_ALIGNMENT_TOLERANCE_DP = 2; +/** + * The widest side gap a footer keeps from the surface edge in landscape. iOS wraps each footer button + * in a SafeAreaView, and an iPhone's landscape side inset is at most 62 pt; Android's LogBoxDialog and + * RedBoxDialogSurfaceDelegate margin the root by the system-bar and cutout insets, 48 dp for a side + * navigation bar. An app's centered button pair sits hundreds of points in. + */ +const FOOTER_LANDSCAPE_SIDE_INSET_MAX_DP = 80; +/** + * Without a surface the side gaps cannot be measured, so only a footer of three or more columns is + * read: LogBox's has three and RedBox's four, while an app's two-button row would pass the spacing. + */ +const FOOTER_MIN_COLUMNS_WITHOUT_SURFACE = 3; export function formatReactNativeOverlayWarning( nodes: SnapshotNode[], @@ -105,36 +115,22 @@ function collectReactNativeOverlayFacts( const collapsedCountBadgeNodes = collapsedNodes.filter((node) => isReactNativeCollapsedWarningCountBadgeBanner(node, surface), ); - const collapsedEvidenceNodes = collapsedNodes.filter((node) => - nodeHasMatchingLabel(node, isReactNativeCollapsedWarningEvidenceLabel), - ); return { dismissNodes, minimizeNodes, collapsedNodes, collapsedCountBadgeNodes, - overlaySurfaceNodes: new Set([ - ...[...collapsedEvidenceNodes, ...collapsedCountBadgeNodes].filter( - isReactNativeCollapsedWarningBanner, - ), - ...nodes.filter( - (node) => - !isFullScreenOverlayRect(node.rect) && - hasKnownReactNativeOverlayText(formatNodeSearchText(node).toLowerCase()), - ), - ]), - footerControlNodes: [ - ...minimizeNodes, - ...collectOverlayNodes(nodes, (label) => REDBOX_FOOTER_CONTROL_PATTERN.test(label)), - ], - nodeByIndex: new Map(nodes.map((node) => [node.index, node])), + footerPartnerNodes: collectOverlayNodes(nodes, (label) => FOOTER_PARTNER_PATTERN.test(label)), + surface, detected: isReactNativeOverlayDetected({ text, hasReactNativeStackFrame, hasOverlayControl, hasControllessRedBoxText, collapsedNodes, - collapsedEvidenceNodes, + collapsedEvidenceNodes: collapsedNodes.filter((node) => + nodeHasMatchingLabel(node, isReactNativeCollapsedWarningEvidenceLabel), + ), collapsedCountBadgeNodes, openDebuggerWarningNodes, }), @@ -157,25 +153,25 @@ function isCollapsedWarningNode( ); } -/** Apps label their own buttons Dismiss and Close too, so overlay evidence outranks role. */ +/** + * Apps name their own buttons Dismiss and Close, so the only control taken is the footer Dismiss of + * LogBox's inspector or of RedBox. A collapsed banner is closed at its own affordance, except while + * the inspector's Dismiss and Minimize are on screen: the banner then lies under the inspector. + */ function resolveSafeDismissAction( facts: ReactNativeOverlayFacts, ): ReactNativeOverlayDismissTarget | null { - const dismiss = selectHighestScoredNode( - facts.dismissNodes.filter((node) => - nodeHasMatchingLabel(node, isReactNativeOverlayDismissLabel), - ), - (node) => [ - booleanScore(isOnOverlaySurface(node, facts) || sharesFooterRow(node, facts)), - ...controlNodeScores(node), - ], - ); - if (dismiss) return targetFromNode(dismiss, 'dismiss'); - - const close = firstControlNodeWithRect( - facts.dismissNodes.filter((node) => isOnOverlaySurface(node, facts)), - ); - if (close) return targetFromNode(close, 'close'); + const footer = findOverlayFooterDismiss(facts); + if (footer) { + return { + action: 'dismiss', + point: centerOfRect(footer.column), + rect: footer.column, + ref: footer.node.ref, + label: readNodeLabel(footer.node), + }; + } + if (isInspectorFooterVocabularyOnScreen(facts)) return null; const collapsed = chooseCollapsedWarningNode( facts.collapsedNodes.filter((node) => isSafeCollapsedWarningCoordinateFallback(node, facts)), @@ -291,69 +287,121 @@ function collectOverlayNodes( return nodes.filter((node) => node.ref && nodeHasMatchingLabel(node, matches)); } -function firstControlNodeWithRect(nodes: SnapshotNode[]): SnapshotNode | null { - return selectHighestScoredNode(nodes, controlNodeScores); -} +type OverlayFooterDismiss = { node: SnapshotNode; column: Rect }; +type RectNode = SnapshotNode & { rect: Rect }; -function isSemanticControlNode(node: ReactNativeOverlayNode): boolean { - const roleText = [node.type, node.role, node.subrole].join(' ').toLowerCase(); - return /\b(button|menuitem|link)\b/.test(roleText); +/** + * LogBox's inspector footer (`flex: 1` buttons) and RedBox's footer (a fill-equally stack view on + * iOS, weighted buttons on Android) give each control an equal column across one row, so Dismiss and + * its partners sit centered at an even spacing. The row may stop short of the surface edges only by + * the side inset a landscape window keeps. A capture hands over the full tile, only its text, or a + * row it folded the Dismiss tile into, labelled Dismiss and holding the other tiles; the target is + * Dismiss's column in each case. A node centered in its own column is preferred over a folded row. + */ +function findOverlayFooterDismiss(facts: ReactNativeOverlayFacts): OverlayFooterDismiss | null { + const tolerance = footerTolerance(facts.surface); + const dismissNodes = facts.dismissNodes.filter( + (node): node is RectNode => + node.rect !== undefined && nodeHasMatchingLabel(node, isReactNativeOverlayDismissLabel), + ); + for (const folded of [false, true]) { + for (const node of dismissNodes) { + const column = footerDismissColumn(node.rect, folded, facts, tolerance); + if (column) return { node, column }; + } + } + return null; } -function controlNodeScores(node: SnapshotNode): number[] { - return [ - booleanScore(isSemanticControlNode(node)), - booleanScore(node.hittable), - -(node.rect ? rectArea(node.rect) : Number.POSITIVE_INFINITY), - ]; +function footerDismissColumn( + rect: Rect, + folded: boolean, + facts: ReactNativeOverlayFacts, + tolerance: number, +): Rect | undefined { + const partnerCenters = footerPartnerCenters(rect, facts.footerPartnerNodes, tolerance); + if (!partnerCenters || partnerCenters.length === 0) return undefined; + let dismissCenter = rect.x + rect.width / 2; + if (folded) { + // The Dismiss slot is the column before the partners, or after them right to left. + if (partnerCenters.length < 2) return undefined; + const spacing = partnerCenters[1]! - partnerCenters[0]!; + const slot = [partnerCenters[0]! - spacing, partnerCenters.at(-1)! + spacing].find( + (center) => center > rect.x && center < rect.x + rect.width, + ); + if (slot === undefined) return undefined; + dismissCenter = slot; + } + const centers = [...partnerCenters, dismissCenter].sort((left, right) => left - right); + const first = centers[0]!; + const spacing = (centers.at(-1)! - first) / (centers.length - 1); + if (centers.some((center, column) => Math.abs(center - (first + column * spacing)) > tolerance)) { + return undefined; + } + const rowStart = first - spacing / 2; + const rowEnd = centers.at(-1)! + spacing / 2; + if (!hasFooterSideGaps(rowStart, rowEnd, centers.length, facts.surface, tolerance)) { + return undefined; + } + return { x: dismissCenter - spacing / 2, y: rect.y, width: spacing, height: rect.height }; } -function targetFromNode( - node: SnapshotNode, - action: ReactNativeOverlayDismissTarget['action'], -): ReactNativeOverlayDismissTarget { - if (!node.rect) { - throw new Error('React Native overlay target node must have rect'); +/** + * One center per partner name in the row, sorted. A capture can list a control twice, as its tile + * and as its text, so a name counts once; a name at two positions is not a footer. + */ +function footerPartnerCenters( + rect: Rect, + partners: SnapshotNode[], + tolerance: number, +): number[] | undefined { + const centersByName = new Map(); + for (const partner of partners) { + if (!partner.rect || !isSameRow(partner.rect, rect, tolerance)) continue; + const name = readNodeLabel(partner)?.trim().toLowerCase().split(/[\s(]/)[0] ?? ''; + const center = partner.rect.x + partner.rect.width / 2; + const known = centersByName.get(name); + if (known !== undefined && Math.abs(known - center) > tolerance) return undefined; + centersByName.set(name, center); } - return { - action, - point: centerOfRect(node.rect), - rect: node.rect, - ref: node.ref, - label: readNodeLabel(node), - }; + return [...centersByName.values()].sort((left, right) => left - right); } -function isOnOverlaySurface(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { - if (hasOverlaySurfaceAncestor(node, facts)) return true; - const rect = node.rect; - if (!rect) return false; - return [...facts.overlaySurfaceNodes].some( - (surface) => surface.rect !== undefined && rectContains(surface.rect, rect), - ); +function hasFooterSideGaps( + rowStart: number, + rowEnd: number, + columns: number, + surface: ReactNativeOverlaySurface | undefined, + tolerance: number, +): boolean { + if (!surface) return columns >= FOOTER_MIN_COLUMNS_WITHOUT_SURFACE; + // Portrait has no side safe-area inset, so the row meets both edges. + const maxGap = + surface.width > surface.height + ? FOOTER_LANDSCAPE_SIDE_INSET_MAX_DP * (surface.rectUnitsPerDp ?? 1) + : tolerance; + return [rowStart, surface.width - rowEnd].every((gap) => gap >= -tolerance && gap <= maxGap); } -function hasOverlaySurfaceAncestor(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { - const visited = new Set(); - let parentIndex = node.parentIndex; - while (typeof parentIndex === 'number' && !visited.has(parentIndex)) { - visited.add(parentIndex); - const parent = facts.nodeByIndex.get(parentIndex); - if (!parent) return false; - if (facts.overlaySurfaceNodes.has(parent)) return true; - parentIndex = parent.parentIndex; - } - return false; +function footerTolerance(surface: ReactNativeOverlaySurface | undefined): number { + return FOOTER_ALIGNMENT_TOLERANCE_DP * (surface?.rectUnitsPerDp ?? 1); +} + +function isSameRow(rect: Rect, other: Rect, tolerance: number): boolean { + return Math.abs(rect.y + rect.height / 2 - (other.y + other.height / 2)) <= tolerance; } -function sharesFooterRow(node: SnapshotNode, facts: ReactNativeOverlayFacts): boolean { - const rect = node.rect; - if (!rect) return false; - return facts.footerControlNodes.some( - (control) => - control.rect !== undefined && - control.rect.y < rect.y + rect.height && - rect.y < control.rect.y + control.rect.height, +/** The inspector's Dismiss and Minimize share its footer row; the banner it opened from stays below. */ +function isInspectorFooterVocabularyOnScreen(facts: ReactNativeOverlayFacts): boolean { + const tolerance = footerTolerance(facts.surface); + return facts.dismissNodes.some( + (dismiss) => + dismiss.rect !== undefined && + nodeHasMatchingLabel(dismiss, isReactNativeOverlayDismissLabel) && + facts.minimizeNodes.some( + (minimize) => + minimize.rect !== undefined && isSameRow(minimize.rect, dismiss.rect!, tolerance), + ), ); } diff --git a/packages/contracts/src/react-native-overlay.ts b/packages/contracts/src/react-native-overlay.ts index 23aa8a68d8..fef8fbc318 100644 --- a/packages/contracts/src/react-native-overlay.ts +++ b/packages/contracts/src/react-native-overlay.ts @@ -206,7 +206,7 @@ function isCloseTo(measured: number, expected: number): boolean { return Math.abs(measured - expected) <= COLLAPSED_BANNER_SIDE_INSET_TOLERANCE; } -export function isFullScreenOverlayRect(rect: RawSnapshotNode['rect']): boolean { +function isFullScreenOverlayRect(rect: RawSnapshotNode['rect']): boolean { if (!rect) return false; return rect.x <= 1 && rect.y <= 1 && rect.width >= 300 && rect.height >= 600; } diff --git a/packages/daemon/src/execution/handlers/__tests__/react-native.test.ts b/packages/daemon/src/execution/handlers/__tests__/react-native.test.ts index 9c96389c2c..4b4ea2a10e 100644 --- a/packages/daemon/src/execution/handlers/__tests__/react-native.test.ts +++ b/packages/daemon/src/execution/handlers/__tests__/react-native.test.ts @@ -26,6 +26,18 @@ const mockCaptureSnapshot = vi.mocked(captureSnapshot); */ const mockDismissTap = mockTapPoint; +/** RCTRedBoxController's footer: one button per label in a fill-equally stack across the window. */ +function redBoxFooter(labels: string[], y: number, windowWidth: number) { + const width = windowWidth / labels.length; + return labels.map((label, column) => ({ + index: column + 1, + ref: `e${column + 2}`, + type: 'XCUIElementTypeButton', + label, + rect: { x: column * width, y, width, height: 44 }, + })); +} + beforeEach(() => { mockCaptureSnapshot.mockReset(); resetGetRuntimeFixture(); @@ -97,7 +109,7 @@ test('react-native dismiss-overlay taps collapsed warning close affordance inste }); }); -test('react-native dismiss-overlay prefers non-trailing collapsed warning close controls', async () => { +test('react-native dismiss-overlay closes a collapsed banner at its own affordance, not at a Close over it', async () => { const sessionName = 'rn-session'; const sessionStore = makeSessionStore(); sessionStore.publish(sessionName, makeSession(sessionName)); @@ -114,6 +126,7 @@ test('react-native dismiss-overlay prefers non-trailing collapsed warning close { index: 1, ref: 'e91', + type: 'Button', label: 'Close', rect: { x: 10, y: 803, width: 34, height: 34 }, hittable: true, @@ -141,13 +154,13 @@ test('react-native dismiss-overlay prefers non-trailing collapsed warning close expect(response?.ok).toBe(true); expect(mockDismissTap).toHaveBeenCalledWith( - expect.objectContaining({ point: { x: 27, y: 820 } }), + expect.objectContaining({ point: { x: 379, y: 820 } }), ); expect(response?.ok && response.data).toMatchObject({ action: 'dismiss-overlay', - overlayAction: 'close', - ref: 'e91', - x: 27, + overlayAction: 'close-collapsed-banner', + ref: 'e90', + x: 379, y: 820, }); }); @@ -332,7 +345,7 @@ test('react-native dismiss-overlay rejects unsafe collapsed warning coordinate f }); }); -test('react-native dismiss-overlay dismisses RedBox error overlays instead of minimizing them', async () => { +test('react-native dismiss-overlay dismisses the LogBox inspector instead of minimizing it', async () => { const sessionName = 'rn-redbox-session'; const sessionStore = makeSessionStore(); sessionStore.publish(sessionName, makeSession(sessionName)); @@ -350,15 +363,22 @@ test('react-native dismiss-overlay dismisses RedBox error overlays instead of mi index: 1, ref: 'e2', label: 'Dismiss', - rect: { x: 20, y: 730, width: 150, height: 44 }, + rect: { x: 0, y: 730, width: 130, height: 44 }, }, { index: 2, ref: 'e3', label: 'Minimize', - rect: { x: 190, y: 730, width: 150, height: 44 }, + rect: { x: 130, y: 730, width: 130, height: 44 }, + }, + { + index: 3, + ref: 'e4', + label: 'Copy', + rect: { x: 260, y: 730, width: 130, height: 44 }, }, ], + viewport: snapshotViewportSizeFrom({ x: 0, y: 0, width: 390, height: 844 }), createdAt: Date.now(), }, }) @@ -387,7 +407,7 @@ test('react-native dismiss-overlay dismisses RedBox error overlays instead of mi expect(response?.ok).toBe(true); expect(mockDismissTap).toHaveBeenCalledWith( - expect.objectContaining({ point: { x: 95, y: 752 } }), + expect.objectContaining({ point: { x: 65, y: 752 } }), ); expect(response?.ok && response.data).toMatchObject({ action: 'dismiss-overlay', @@ -397,13 +417,13 @@ test('react-native dismiss-overlay dismisses RedBox error overlays instead of mi verified: true, verificationRequired: false, message: 'React Native overlay dismiss action sent and verified gone', - x: 95, + x: 65, y: 752, }); expect(response?.ok && response.data?.minimized).toBeUndefined(); }); -test('react-native dismiss-overlay reports unverified dismiss when RedBox controls remain', async () => { +test('react-native dismiss-overlay reports unverified dismiss when the inspector controls remain', async () => { const sessionName = 'rn-redbox-still-full-session'; const sessionStore = makeSessionStore(); sessionStore.publish(sessionName, makeSession(sessionName)); @@ -420,15 +440,22 @@ test('react-native dismiss-overlay reports unverified dismiss when RedBox contro index: 1, ref: 'e2', label: 'Dismiss', - rect: { x: 20, y: 730, width: 150, height: 44 }, + rect: { x: 0, y: 730, width: 130, height: 44 }, }, { index: 2, ref: 'e3', label: 'Minimize', - rect: { x: 190, y: 730, width: 150, height: 44 }, + rect: { x: 130, y: 730, width: 130, height: 44 }, + }, + { + index: 3, + ref: 'e4', + label: 'Copy', + rect: { x: 260, y: 730, width: 130, height: 44 }, }, ], + viewport: snapshotViewportSizeFrom({ x: 0, y: 0, width: 390, height: 844 }), createdAt: Date.now(), }, }; @@ -478,13 +505,9 @@ test('react-native dismiss-overlay uses Dismiss when RedBox Minimize is absent', label: 'Runtime Error', rect: { x: 0, y: 0, width: 390, height: 100 }, }, - { - index: 1, - ref: 'e2', - label: 'Dismiss', - rect: { x: 20, y: 730, width: 150, height: 44 }, - }, + ...redBoxFooter(['Dismiss', 'Reload JS', 'Copy', 'Extra Info'], 730, 390), ], + viewport: snapshotViewportSizeFrom({ x: 0, y: 0, width: 390, height: 844 }), createdAt: Date.now(), }, }); @@ -507,7 +530,7 @@ test('react-native dismiss-overlay uses Dismiss when RedBox Minimize is absent', expect(response?.ok).toBe(true); expect(mockDismissTap).toHaveBeenCalledWith( - expect.objectContaining({ point: { x: 95, y: 752 } }), + expect.objectContaining({ point: { x: 49, y: 752 } }), ); expect(response?.ok && response.data).toMatchObject({ action: 'dismiss-overlay', @@ -530,13 +553,13 @@ test('react-native dismiss-overlay accepts RedBox control labels with keyboard s label: 'Runtime Error: NativeModule is null', rect: { x: 0, y: 0, width: 390, height: 620 }, }, - { - index: 1, - ref: 'e2', - label: 'Dismiss (ESC)', - rect: { x: 18, y: 700, width: 104, height: 44 }, - }, + ...redBoxFooter( + ['Dismiss (ESC)', 'Reload JS (⌘R)', 'Copy (⌥⌘C)', 'Extra Info (⌘E)'], + 700, + 390, + ), ], + viewport: snapshotViewportSizeFrom({ x: 0, y: 0, width: 390, height: 844 }), createdAt: Date.now(), }, }); @@ -559,7 +582,7 @@ test('react-native dismiss-overlay accepts RedBox control labels with keyboard s expect(response?.ok).toBe(true); expect(mockDismissTap).toHaveBeenCalledWith( - expect.objectContaining({ point: { x: 70, y: 722 } }), + expect.objectContaining({ point: { x: 49, y: 722 } }), ); expect(response?.ok && response.data).toMatchObject({ action: 'dismiss-overlay', @@ -594,9 +617,31 @@ test('react-native dismiss-overlay prefers concrete RedBox buttons over labeled ref: 'e43', type: 'XCUIElementTypeButton', label: 'Dismiss (ESC)', - rect: { x: 156, y: 805, width: 90, height: 44 }, + rect: { x: 0, y: 805, width: 100.5, height: 44 }, + }, + { + index: 3, + ref: 'e44', + type: 'XCUIElementTypeButton', + label: 'Reload JS (⌘R)', + rect: { x: 100.5, y: 805, width: 100.5, height: 44 }, + }, + { + index: 4, + ref: 'e45', + type: 'XCUIElementTypeButton', + label: 'Copy (⌥⌘C)', + rect: { x: 201, y: 805, width: 100.5, height: 44 }, + }, + { + index: 5, + ref: 'e46', + type: 'XCUIElementTypeButton', + label: 'Extra Info (⌘E)', + rect: { x: 301.5, y: 805, width: 100.5, height: 44 }, }, ], + viewport: snapshotViewportSizeFrom({ x: 0, y: 0, width: 402, height: 874 }), createdAt: Date.now(), }, }); @@ -622,7 +667,7 @@ test('react-native dismiss-overlay prefers concrete RedBox buttons over labeled action: 'dismiss-overlay', overlayAction: 'dismiss', ref: 'e43', - x: 201, + x: 50, y: 827, }); }); @@ -638,14 +683,8 @@ test('react-native dismiss-overlay reports verified success after a clean post-d { index: 0, ref: 'e1', - label: 'LogBox', - rect: { x: 0, y: 640, width: 390, height: 120 }, - }, - { - index: 1, - ref: 'e2', - label: 'Close', - rect: { x: 84, y: 692, width: 42, height: 44 }, + label: '!, Warning: Failed prop type', + rect: { x: 10, y: 640, width: 370, height: 48 }, }, ], createdAt: Date.now(), @@ -687,7 +726,7 @@ test('react-native dismiss-overlay reports verified success after a clean post-d expect(mockCaptureSnapshot).toHaveBeenCalledTimes(2); expect(response.data).toMatchObject({ action: 'dismiss-overlay', - overlayAction: 'close', + overlayAction: 'close-collapsed-banner', verified: true, verificationRequired: false, }); @@ -773,14 +812,8 @@ test('react-native dismiss-overlay reports unverified dismiss when post-dismiss { index: 0, ref: 'e1', - label: 'LogBox', - rect: { x: 0, y: 640, width: 390, height: 120 }, - }, - { - index: 1, - ref: 'e2', - label: 'Close', - rect: { x: 84, y: 692, width: 42, height: 44 }, + label: '!, Warning: Failed prop type', + rect: { x: 10, y: 640, width: 370, height: 48 }, }, ], createdAt: Date.now(), @@ -841,14 +874,8 @@ test('react-native dismiss-overlay reports still-visible overlays with recovery { index: 0, ref: 'e1', - label: 'LogBox', - rect: { x: 0, y: 640, width: 390, height: 120 }, - }, - { - index: 1, - ref: 'e2', - label: 'Close', - rect: { x: 84, y: 692, width: 42, height: 44 }, + label: '!, Warning: Failed prop type', + rect: { x: 10, y: 640, width: 370, height: 48 }, }, ], createdAt: Date.now(), From 38ae926dac9b3fae145c45d7d6fd7c2474f83abe Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 23 Nov 2026 21:46:12 +0530 Subject: [PATCH 3/3] fix(capture-kit): try footer candidates from the end of the capture Footer membership is read from geometry, so a full-width app bar with equal columns labelled Dismiss and Copy, Reload or Minimize can match. The simulator accessibility capture lists the LogBox and RedBox windows after the app's, so the candidates are now tried from the end of the capture and the real footer wins there. A row is listed before the tiles it holds, so a tile, or its text, is still taken before the row folded around it. --- .../src/react-native-overlay.test.ts | 30 ++++++++++++++++--- .../capture-kit/src/react-native-overlay.ts | 16 ++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/capture-kit/src/react-native-overlay.test.ts b/packages/capture-kit/src/react-native-overlay.test.ts index bce304453a..c82fad4fec 100644 --- a/packages/capture-kit/src/react-native-overlay.test.ts +++ b/packages/capture-kit/src/react-native-overlay.test.ts @@ -471,6 +471,24 @@ describe('React Native overlay dismissal beside app Close and Dismiss buttons', }); }); + test('synthetic: a full-width app bar listed before the inspector footer loses to it', () => { + // The simulator accessibility capture lists the LogBox window after the app's. + const bar = (index: number, label: string, x: number) => + node({ + index, + ref: `e${index}`, + type: 'Button', + label, + rect: { x, y: 100, width: 201, height: 44 }, + }); + const state = analyzeReactNativeOverlay( + [bar(20, 'Dismiss', 0), bar(21, 'Copy', 201), componentStackText, ...inspectorFooter], + viewport, + ); + + expect(state.primaryAction).toMatchObject({ action: 'dismiss', ref: 'e60' }); + }); + test.each([ { direction: 'left-to-right', minimizeX: 134, copyX: 268, tapX: 67 }, { direction: 'right-to-left', minimizeX: 134, copyX: 0, tapX: 335 }, @@ -878,10 +896,10 @@ describe('React Native overlay dismissal beside app Close and Dismiss buttons', rect: { x: centerX - width / 2, y: 2213, width, height: 53 }, }); const footerTexts = [ - // Text sits a few pixels off its column's center, within 2 dp at this density. + // The Dismiss text sits a few pixels off its column's center, within 2 dp at this density. text(70, 'Dismiss', 183, 160), - text(71, 'Minimize', 543, 182), - text(72, 'Copy', 897, 102), + text(71, 'Minimize', 540, 182), + text(72, 'Copy', 900, 102), ]; const footerTiles = ['Dismiss', 'Minimize', 'Copy'].map((label, column) => node({ @@ -936,7 +954,11 @@ describe('React Native overlay dismissal beside app Close and Dismiss buttons', surface, ); - expect(state.primaryAction).toMatchObject({ action: 'dismiss', point: { x: 180 } }); + expect(state.primaryAction).toMatchObject({ + action: 'dismiss', + ref: 'e70', + point: { x: 183 }, + }); }); test('in landscape, a footer inset by the cutout and the navigation bar is still read', () => { diff --git a/packages/capture-kit/src/react-native-overlay.ts b/packages/capture-kit/src/react-native-overlay.ts index 01d021e937..cb31eef7f5 100644 --- a/packages/capture-kit/src/react-native-overlay.ts +++ b/packages/capture-kit/src/react-native-overlay.ts @@ -296,7 +296,11 @@ type RectNode = SnapshotNode & { rect: Rect }; * its partners sit centered at an even spacing. The row may stop short of the surface edges only by * the side inset a landscape window keeps. A capture hands over the full tile, only its text, or a * row it folded the Dismiss tile into, labelled Dismiss and holding the other tiles; the target is - * Dismiss's column in each case. A node centered in its own column is preferred over a folded row. + * Dismiss's column in each case. + * + * Candidates are tried from the end of the capture. The simulator accessibility capture lists the + * LogBox and RedBox windows after the app's, so an app bar shaped like a footer loses to the real one + * there, and a row is listed before the tiles it holds, so a tile wins over the row folded around it. */ function findOverlayFooterDismiss(facts: ReactNativeOverlayFacts): OverlayFooterDismiss | null { const tolerance = footerTolerance(facts.surface); @@ -304,11 +308,11 @@ function findOverlayFooterDismiss(facts: ReactNativeOverlayFacts): OverlayFooter (node): node is RectNode => node.rect !== undefined && nodeHasMatchingLabel(node, isReactNativeOverlayDismissLabel), ); - for (const folded of [false, true]) { - for (const node of dismissNodes) { - const column = footerDismissColumn(node.rect, folded, facts, tolerance); - if (column) return { node, column }; - } + for (const node of [...dismissNodes].reverse()) { + const column = + footerDismissColumn(node.rect, false, facts, tolerance) ?? + footerDismissColumn(node.rect, true, facts, tolerance); + if (column) return { node, column }; } return null; }