Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/capture-kit/src/screenshot-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { type SnapshotState } from '@agent-device/contracts/snapshot-model';
import { decodePngAsync, encodePngAsync } from './png-worker-client.ts';
import {
projectSnapshotRectToScreenshot,
resolveScreenshotFrame,
resolveSnapshotBounds,
} from './snapshot-rect-projection.ts';
import { analyzeReactNativeOverlay } from './react-native-overlay.ts';
Expand Down Expand Up @@ -270,10 +271,21 @@ function projectRectToScreenshot(
screenshotHeight: number,
): Rect {
const space = snapshot.backend === 'android' ? 'device-pixels' : 'viewport-points';
const frame = resolveScreenshotFrame(
{ width: screenshotWidth, height: screenshotHeight },
snapshot,
);
return clampRect(
projectSnapshotRectToScreenshot(space, bounds, rect, screenshotWidth, screenshotHeight),
screenshotWidth,
screenshotHeight,
projectSnapshotRectToScreenshot(
space,
bounds,
rect,
screenshotWidth,
screenshotHeight,
snapshot.captureScale,
),
frame.width,
frame.height,
);
}

Expand Down
14 changes: 13 additions & 1 deletion packages/capture-kit/src/snapshot-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type PresentedSurface,
type RawSnapshotNode,
type SnapshotKeyboardBandFact,
type SnapshotCaptureScale,
type SnapshotViewportSize,
type SnapshotQualityNote,
} from '@agent-device/kernel/snapshot';
Expand Down Expand Up @@ -75,6 +76,8 @@ export function buildSnapshotState(
keyboard?: SnapshotKeyboardBandFact;
/** The box the producer measured the rects in (#3182), carried to the response that reads this state. */
viewport?: SnapshotViewportSize;
/** Screenshot pixels per rect unit, carried beside `viewport` to every projection of this state. */
captureScale?: SnapshotCaptureScale;
/**
* iOS: the producer's reading of a modal presentation over the app (#3565), decided on the
* acquired tree so every projection of one screen carries the same value.
Expand Down Expand Up @@ -129,7 +132,7 @@ export function buildSnapshotState(
...(data.presentedSurface ? { presentedSurface: data.presentedSurface } : {}),
...(data.targetActivation ? { targetActivation: data.targetActivation } : {}),
...(data.keyboard ? { keyboard: data.keyboard } : {}),
...(data.viewport ? { viewport: data.viewport } : {}),
...snapshotStateGeometry(data),
presentationKey: buildSnapshotPresentationKey(presentation),
presentation,
// Only broad Android snapshots become freshness baselines. If the user asked for a scoped
Expand All @@ -139,6 +142,15 @@ export function buildSnapshotState(
};
}

function snapshotStateGeometry(
data: Readonly<{ viewport?: SnapshotViewportSize; captureScale?: SnapshotCaptureScale }>,
): Pick<SnapshotState, 'viewport' | 'captureScale'> {
return {
...(data.viewport ? { viewport: data.viewport } : {}),
...(data.captureScale ? { captureScale: data.captureScale } : {}),
};
}

/**
* The hint a node carries when the rect it is published with has no area. That is not evidence
* that the node is off screen, but nothing confirms that it is on screen either: a scroll view
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/src/snapshot-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
SnapshotQualityNote,
SnapshotQualityVerdict,
SnapshotRefMinting,
SnapshotCaptureScale,
SnapshotViewportSize,
} from '@agent-device/kernel/snapshot';
import {
Expand Down Expand Up @@ -136,6 +137,12 @@ export type SnapshotState = {
* producer measured instead of inferring one from the largest rect still on screen.
*/
viewport?: SnapshotViewportSize;
/**
* Screenshot pixels per rect unit, when the producer published one (a TV app page's CSS px). The
* state carries it beside `viewport` so every projection of a stored tree onto a capture uses the
* producer's scale. See {@link SnapshotCaptureScale}.
*/
captureScale?: SnapshotCaptureScale;
/**
* iOS: this capture's own command found the session app out of foreground and the runner
* activated it before answering, so an earlier observation in the session described whatever held
Expand Down
49 changes: 40 additions & 9 deletions packages/daemon/src/execution/screenshot-runtime-execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,18 @@ const TV_PAGE_TREE: RawSnapshotNode[] = [
},
];

async function cropProviderTv(page: {
type ProviderTvPage = {
producer?: 'cdp-dom' | 'android-uiautomator';
captureScale: number;
viewport: { width: number; height: number };
cropOn?: string;
}) {
const { producer = 'cdp-dom', cropOn = 'label="Save"' } = page;
};

async function cropProviderTv(page: ProviderTvPage & { cropOn?: string }) {
return await screenshotProviderTv(page, { screenshotCropOn: page.cropOn ?? 'label="Save"' });
}

async function screenshotProviderTv(page: ProviderTvPage, flags: DaemonRequest['flags']) {
const { producer = 'cdp-dom' } = page;
const captureScale = snapshotCaptureScaleFrom(page.captureScale);
const viewport = snapshotViewportSizeFrom({ x: 0, y: 0, ...page.viewport });
const fixture = screenshotRuntimeFixture({
Expand All @@ -676,11 +681,8 @@ async function cropProviderTv(page: {
}),
});
const session = makeSession('tv', { device: PROVIDER_TV });
const outPath = path.join(mkdtempForTestSync('provider-tv-crop'), 'tv.png');
const req = screenshotRequest({
positionals: [outPath],
flags: { screenshotCropOn: cropOn },
});
const outPath = path.join(mkdtempForTestSync('provider-tv-screenshot'), 'tv.png');
const req = screenshotRequest({ positionals: [outPath], flags });
const resolved = await resolveScreenshotGenericExecution({
hostCwd: process.cwd(),
createCommandSurface: testCreateCommandSurface,
Expand Down Expand Up @@ -720,6 +722,35 @@ test('a provider TV crop clips a node at the page edge to the page, not to the l
]);
});

test("provider TV overlay refs are drawn at the page's capture scale", async () => {
const result = await screenshotProviderTv(
{ captureScale: 1.5, viewport: PAGE_720 },
{ overlayRefs: true },
);

expect(result.overlayRefs).toContainEqual(
expect.objectContaining({
label: 'Save',
rect: { x: 10, y: 10, width: 40, height: 20 },
overlayRect: { x: 15, y: 15, width: 60, height: 30 },
}),
);
});

test('provider TV overlay refs stop at the page edge, not at the larger capture', async () => {
const result = await screenshotProviderTv(
{ captureScale: 1, viewport: PAGE_720 },
{ overlayRefs: true },
);

expect(result.overlayRefs).toContainEqual(
expect.objectContaining({
label: 'Tile',
overlayRect: { x: 1200, y: 100, width: 80, height: 200 },
}),
);
});

test('a provider TV crop is refused on a tree the TV plugins did not capture', async () => {
await expect(
cropProviderTv({ producer: 'android-uiautomator', captureScale: 1, viewport: PAGE_720 }),
Expand Down
5 changes: 3 additions & 2 deletions packages/provider-tizen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ Not yet: system buttons (`home`, menu, volume and channel), `network dump`, `per
- **Snapshots are DOM-derived.** Labels come from `aria-label`, `alt`, `title` or own text; rects
are CSS px. The screenshot magnifies them by the page's `visualViewport.scale`: a `width=1280`
meta viewport on a 1920x1080 TV gives 1.5. `screenshot --crop-on` applies that scale, and refuses
a page whose browser has no `visualViewport` or whose visual viewport is panned. The walk does not
enter iframes or shadow roots. `is text` on an input compares its label, not its value; the value
a page whose browser has no `visualViewport` or whose visual viewport is panned.
`screenshot --overlay-refs` draws ref boxes at the same scale; without one it draws them 1:1. The
walk does not enter iframes or shadow roots. `is text` on an input compares its label, not its value; the value
is in `snapshot --raw`.
- **System overlays are outside the page.** The Samsung menu, on-screen keyboard and other system
layers never appear in `screenshot` or `snapshot`.
5 changes: 3 additions & 2 deletions packages/provider-webos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ in `open`, `power`. webOS has separate Play and Pause key codes and no play-paus
1920x1080 TV, an app at `"resolution": "1280x720"` reports 1.5 yet fills only the top-left
1280x720 of the capture. `screenshot --crop-on` scales rects by the page's `visualViewport.scale`,
which is 1 because webOS ignores the meta viewport, and clips the crop to the page. It refuses a
page whose browser has no `visualViewport` or whose visual viewport is panned. The walk does not
enter iframes or shadow roots, so overlays rendered there (for example a dev-server error overlay)
page whose browser has no `visualViewport` or whose visual viewport is panned.
`screenshot --overlay-refs` draws ref boxes at the same scale and stops them at the page edge. The
walk does not enter iframes or shadow roots, so overlays rendered there (for example a dev-server error overlay)
appear in screenshots but not in snapshots.
- **`click`, `press`, `fill` and `focus` refuse a control marked `[covered]`.** A tap at its
centre would land on the element on top, such as a card's own pressable area. `snapshot -i`
Expand Down
5 changes: 3 additions & 2 deletions website/docs/docs/tizen.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ Not supported yet: system buttons (`home`, menu, volume, and channel), `network
- Snapshots are read from the DOM. Labels come from `aria-label`, `alt`, `title`, or own text. Rects
are CSS pixels. The screenshot magnifies them by the page's `visualViewport.scale`: a `width=1280`
meta viewport on a 1920x1080 TV gives 1.5. `screenshot --crop-on` applies that scale, and refuses
a page whose browser has no `visualViewport` or whose visual viewport is panned. The walk does not
enter iframes or shadow roots.
a page whose browser has no `visualViewport` or whose visual viewport is panned.
`screenshot --overlay-refs` draws ref boxes at the same scale; without one it draws them 1:1. The
walk does not enter iframes or shadow roots.
5 changes: 3 additions & 2 deletions website/docs/docs/webos.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ play-pause toggle, so `media-play-pause` is refused; use `media-play` or `media-
on a 1920x1080 TV, an app at `"resolution": "1280x720"` reports 1.5 yet fills only the top-left
1280x720 of the capture. `screenshot --crop-on` scales rects by the page's `visualViewport.scale`,
which is 1 because webOS ignores the meta viewport, and clips the crop to the page. It refuses a
page whose browser has no `visualViewport` or whose visual viewport is panned. The walk does not
enter iframes or shadow roots.
page whose browser has no `visualViewport` or whose visual viewport is panned.
`screenshot --overlay-refs` draws ref boxes at the same scale and stops them at the page edge. The
walk does not enter iframes or shadow roots.
- `click`, `press`, `fill`, and `focus` refuse a control marked `[covered]`, because a tap at its
centre would land on the element on top, such as a card's own pressable area. `snapshot -i` still
lists it, and `tv-remote` reaches it through focus.
Loading