Skip to content

Commit a32d5e0

Browse files
dhruvkelawalaclaude
andcommitted
fix(ios): refuse scene-hosted remote content in bridge snapshots
On iOS 26 a share or action extension presented over its host app reaches the host's accessibility tree as one AXRemoteElement leaf under a _UISceneHostingView; its controls live in the extension's process. The single-process bridge published that leaf as if the screen were complete, so a snapshot of Photos with a share extension up returned one `other "Photos"` node. Count such leaves as opaque remote content, as web-hosted leaves already are (#2484), so the route serves the XCTest runner, which resolves them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 81f4666 commit a32d5e0

5 files changed

Lines changed: 83 additions & 27 deletions

File tree

‎docs/adr/0004-ios-snapshot-backend-strategy.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ such a leaf sits under a `WebView`-typed ancestor and reaches the viewport (`rem
4949
instead of publishing a screen without its page: refs issued from it would target the host views
5050
around the page rather than the page. A leaf whose frame is zero-area or off screen hosts nothing
5151
the capture can miss and is published; one that reports no frame is refused, because nothing proves
52-
it empty. Remote elements outside a web view are not classified — no capture has shown one — and a
53-
web view truncated away by the node or depth cap stays disclosed as truncation. XCTest resolves
54-
remote elements, so the fallback serves the page (#2484).
52+
it empty. A scene-hosted remote view controller — a share or action extension presented over the
53+
host app — reaches the tree the same way: an `AXRemoteElement` leaf under a `_UISceneHostingView`,
54+
with the extension's controls in its own process. The source refuses that leaf by the same rule.
55+
Remote elements under any other host are not classified — no capture has shown one — and a host
56+
truncated away by the node or depth cap stays disclosed as truncation. XCTest resolves remote
57+
elements, so the fallback serves the page or the extension (#2484).
5558

5659
The refusal opens the generation circuit, as any failure that says something about the app itself
5760
does, so a hybrid app that showed one web screen takes XCTest for its remaining native screens until

‎packages/platform-apple/src/snapshot-source/adapter.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ function createAcquisition(
211211
if (typeof generation !== 'string' || !generation) {
212212
throw snapshotSourceError('malformed-tree', 'generation-invalid');
213213
}
214-
// A tree that ends at a web view's out-of-process page would present the screen without the
215-
// page, and refs issued from it would target the host views around it rather than the page.
214+
// A tree that ends at out-of-process content — a web view's page, or a scene-hosted extension —
215+
// would present the screen without it, and refs issued from it would target the host views around
216+
// it rather than the content.
216217
// The source refuses it as a screen it cannot describe, like a missing automation mode, so the
217218
// route serves the XCTest runner, which resolves remote elements (#2484).
218219
if (decoded.opaqueRemoteElements > 0) {

‎packages/platform-apple/src/snapshot-source/tree.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ test('the bridge tree counts web-hosted remote leaves that reach the viewport',
222222
decode({ [automationType]: 0, [frame]: viewport, [children]: [remoteLeaf(viewport)] })
223223
.opaqueRemoteElements,
224224
0,
225-
'a remote leaf outside a web view is not classified',
225+
'a remote leaf outside a remote-content host is not classified',
226226
);
227227
assert.equal(
228228
decode(
@@ -236,6 +236,48 @@ test('the bridge tree counts web-hosted remote leaves that reach the viewport',
236236
);
237237
});
238238

239+
test('the bridge tree counts scene-hosted remote leaves that reach the viewport', () => {
240+
// A share extension presented over Photos on iOS 26: the extension's controls live in its own
241+
// process, under the host app's scene-hosting view, and the reader stops at the remote element.
242+
const viewport = { X: 0, Y: 0, Width: 402, Height: 874 };
243+
const sceneHosted = (rect?: Record<string, number>) => ({
244+
[application]: '_UISceneHostingView',
245+
[frame]: viewport,
246+
[children]: [
247+
{
248+
[application]: '_UIScenePresentationView',
249+
[frame]: viewport,
250+
[children]: [
251+
{
252+
[application]: 'AXRemoteElement',
253+
[baseType]: 'NSObject',
254+
...(rect ? { [frame]: rect } : {}),
255+
[children]: [],
256+
},
257+
],
258+
},
259+
],
260+
});
261+
const decode = (host: Record<string, unknown>) =>
262+
decodeSnapshotBridgeTree(
263+
{ [application]: 'PhotosApplication', [frame]: viewport, [children]: [host] },
264+
{ truncated: false },
265+
limits,
266+
);
267+
268+
const opaque = decode(sceneHosted(viewport));
269+
assert.equal(opaque.nodes[1]?.role, '_UISceneHostingView');
270+
assert.equal(opaque.nodes[3]?.role, 'AXRemoteElement');
271+
assert.equal(opaque.opaqueRemoteElements, 1);
272+
273+
assert.equal(decode(sceneHosted()).opaqueRemoteElements, 1, 'frameless leaf refuses');
274+
assert.equal(
275+
decode(sceneHosted({ X: 0, Y: 0, Width: 0, Height: 0 })).opaqueRemoteElements,
276+
0,
277+
'a dismissed extension leaves a zero-area leaf that hosts nothing',
278+
);
279+
});
280+
239281
test('the bridge tree reads enabled from the NotEnabled trait', () => {
240282
const button = (word?: unknown) => ({
241283
[automationType]: 9,

‎packages/platform-apple/src/snapshot-source/tree.ts‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,25 @@ const SELECTED_TRAIT = 1n << 3n;
140140
const KEYBOARD_FOCUS_TRAIT = 1n << 21n;
141141

142142
/**
143-
* A WebKit page — Safari's, or a `WKWebView`'s — lives in a WebContent process and reaches UIKit's
144-
* tree as an `AXRemoteElement` under the web view, with its children in that other process. The
145-
* guest reader snapshots one process, so it delivers that element as a leaf (#2484). Such a leaf
146-
* is opaque when it sits under a `WebView`-typed ancestor and its frame reaches the viewport: the
147-
* page is on screen and the tree does not describe it. A leaf whose frame is zero-area or off
148-
* screen hosts nothing the capture can miss; one that reports no frame at all is refused, because
149-
* nothing proves it is empty. Remote elements outside a web view are not classified here — no
150-
* capture has shown one — and content truncated away above the web view stays disclosed as
151-
* truncation, not as a boundary.
143+
* Two hosts put another process's UI into this one's tree as an `AXRemoteElement`, with the
144+
* children in that other process:
145+
*
146+
* - a WebKit page — Safari's, or a `WKWebView`'s — lives in a WebContent process under the web
147+
* view (#2484);
148+
* - a scene-hosted remote view controller, such as a share or action extension presented over the
149+
* host app, lives in the extension's process under a `_UISceneHostingView`.
150+
*
151+
* The guest reader snapshots one process, so it delivers that element as a leaf. Such a leaf is
152+
* opaque when it sits under one of those hosts and its frame reaches the viewport: the content is
153+
* on screen and the tree does not describe it. A leaf whose frame is zero-area or off screen hosts
154+
* nothing the capture can miss; one that reports no frame at all is refused, because nothing proves
155+
* it is empty. Remote elements under any other host are not classified here — no capture has shown
156+
* one — and content truncated away above the host stays disclosed as truncation, not as a boundary.
152157
*/
153158
const REMOTE_ELEMENT_CLASS = 'AXRemoteElement';
154159
const EMPTY_RECT: Rect = { x: 0, y: 0, width: 0, height: 0 };
155160
const WEB_VIEW_TYPE = 'WebView';
161+
const SCENE_HOSTING_VIEW_CLASS = '_UISceneHostingView';
156162

157163
export function decodeSnapshotBridgeTree(
158164
tree: unknown,
@@ -164,7 +170,7 @@ export function decodeSnapshotBridgeTree(
164170
throw snapshotSourceError('malformed-tree', 'guest-tree-root-invalid');
165171
}
166172
const nodes: RawSnapshotNode[] = [];
167-
const webHostedRemoteLeaves: (Rect | undefined)[] = [];
173+
const hostedRemoteLeaves: (Rect | undefined)[] = [];
168174
let maxTraversalDepth = 0;
169175
for (const root of roots) {
170176
visitNode(root, undefined, 0, false);
@@ -198,7 +204,7 @@ export function decodeSnapshotBridgeTree(
198204
nodes,
199205
maxTraversalDepth,
200206
viewport,
201-
opaqueRemoteElements: webHostedRemoteLeaves.filter((rect) => isOpaqueRemoteLeaf(rect, viewport))
207+
opaqueRemoteElements: hostedRemoteLeaves.filter((rect) => isOpaqueRemoteLeaf(rect, viewport))
202208
.length,
203209
unresolvedCoordinateSpaceWindows: countUnresolvedCoordinateSpaceWindows(nodes, viewport),
204210
};
@@ -207,7 +213,7 @@ export function decodeSnapshotBridgeTree(
207213
value: Record<string, unknown>,
208214
parentIndex: number | undefined,
209215
depth: number,
210-
underWebView: boolean,
216+
underRemoteHost: boolean,
211217
): void {
212218
if (nodes.length >= limits.maxNodes) {
213219
throw snapshotSourceError('malformed-tree', 'node-limit-exceeded', {
@@ -227,13 +233,13 @@ export function decodeSnapshotBridgeTree(
227233
const node = nodeFacts(value, index, parentIndex, depth);
228234
nodes.push(node);
229235
maxTraversalDepth = Math.max(maxTraversalDepth, depth);
230-
if (isWebHostedRemoteLeaf(node, children.length, underWebView)) {
231-
webHostedRemoteLeaves.push(node.rect);
236+
if (isHostedRemoteLeaf(node, children.length, underRemoteHost)) {
237+
hostedRemoteLeaves.push(node.rect);
232238
}
233-
const hostsWeb = underWebView || node.type === WEB_VIEW_TYPE;
239+
const hostsRemote = underRemoteHost || isRemoteContentHost(node);
234240
for (const child of children) {
235241
if (!isRecord(child)) throw snapshotSourceError('malformed-tree', 'child-invalid');
236-
visitNode(child, index, depth + 1, hostsWeb);
242+
visitNode(child, index, depth + 1, hostsRemote);
237243
}
238244
}
239245
}
@@ -299,12 +305,16 @@ function elementTypeName(
299305
return ELEMENT_TYPE_NAMES[automationType] ?? 'Other';
300306
}
301307

302-
function isWebHostedRemoteLeaf(
308+
function isRemoteContentHost(node: RawSnapshotNode): boolean {
309+
return node.type === WEB_VIEW_TYPE || node.role === SCENE_HOSTING_VIEW_CLASS;
310+
}
311+
312+
function isHostedRemoteLeaf(
303313
node: RawSnapshotNode,
304314
childCount: number,
305-
underWebView: boolean,
315+
underRemoteHost: boolean,
306316
): boolean {
307-
return underWebView && node.role === REMOTE_ELEMENT_CLASS && childCount === 0;
317+
return underRemoteHost && node.role === REMOTE_ELEMENT_CLASS && childCount === 0;
308318
}
309319

310320
function isOpaqueRemoteLeaf(rect: Rect | undefined, viewport: IosViewportEvidence): boolean {

‎packages/platform-apple/src/snapshot-source/types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export type SnapshotSourceDecodedTree = Readonly<{
126126
viewport: IosViewportEvidence;
127127
maxTraversalDepth: number;
128128
/**
129-
* `AXRemoteElement` leaves under a web view whose frame reaches the viewport, or that report no
130-
* frame: pages the reader could not cross into (#2484).
129+
* `AXRemoteElement` leaves under a web view or a scene-hosting view whose frame reaches the
130+
* viewport, or that report no frame: pages and extensions the reader could not cross into (#2484).
131131
*/
132132
opaqueRemoteElements: number;
133133
/**

0 commit comments

Comments
 (0)