Skip to content

feat(screenshot): support selector crops on Tizen and webOS TVs - #4635

Merged
thymikee merged 1 commit into
callstack:mainfrom
alimek:feat/tv-screenshot-crop
Nov 17, 2026
Merged

thymikee merged 1 commit into
callstack:mainfrom
alimek:feat/tv-screenshot-crop

Conversation

@alimek

@alimek alimek commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

screenshot --crop-on was refused on Tizen and webOS TVs (provider-owned Android TV devices).

 classifyScreenshotCropTarget(android)
+  tv device, provider-owned → provider-android-tv
 tv-cdp snapshot
+  captureScale = visualViewport.scale; viewport = inner size
 cropScreenshotToSelector
+  assertScreenshotCropSnapshot   # cdp-dom, both facts
-  rects 1:1, clipped to the image
+  rects × captureScale, clipped to viewport × captureScale

TV captures don't follow devicePixelRatio (webOS 1280×720 app: 1.5, unscaled, top-left; Tizen 1280 meta viewport: 1, captured at 1.5×). visualViewport.scale matches both.

24 files, no linked issue. Scope expansion: TV snapshots publish viewport (CSS px). Follow-up: --overlay-refs on TVs.

Validation

Evidence: 1de5b2a2c on 80075b641, rebased onto fdf595127 as a20e4e38f (help/README conflicts); CI validates that head, whose lockfile won't install here.

  • check:affected --run --head 1de5b2a2c: static checks, build, vitest-related (406/406) pass; unit's 6 failures also fail on unchanged base.
  • Mutations: removing the scale, page clip, or missing-fact refusal fails its leaf test.
  • Hardware (static fixture; crop located by border pixels in a plain screenshot): pixel-identical, unique match, every ±4 px shift differs.
    • webOS 22 (32LQ6300), 1920×1080 and 1280×720 apps: 400×240 at (200,300).
    • Tizen 9.0 (M7): 400×240 at (200,300); 1280 meta viewport: 600×360 at (300,450), where 1:1 missed.
    • Page-edge nodes clip to the page, with a warning.

Screenshots:

  • Tizen, 1280 meta viewport:
tizen-1280-full
  • Tizen crop before / after:
tizen-1280-crop-before tizen-1280-crop-after
  • webOS 1280×720, edge crop:
webos-720-full webos-720-edge-crop

Risks: TVs without visualViewport refuse the crop; panned-viewport refusal is hardware-untested.

Two-way door. Blast radius: TV plugins.

🤖 Generated with Claude Code

@thymikee

Copy link
Copy Markdown
Member

The code at 1842881 looks ready, and I found no problems that need a change. Hardware pixel-identity evidence on webOS 22 and Tizen 9.0 comes from the PR body, which says it ran on the pre-rebase commit. Could you confirm that Page.captureScreenshot scales by visualViewport.scale rather than devicePixelRatio on these Chromium builds? The Numeric Ranges check fails with one error caused by this diff: it cannot verify the number input to roundRect at snapshot-rect-projection.ts:55, on the new rect.x * captureScale branch. Please give captureScale a positive finite type from one kernel constructor, as snapshotViewportSizeFrom does for the viewport, instead of a local guard. Once the check is green, nothing else stands in the way of merge.

Not blocking, and you can take or leave these: runtime.test.ts:497 answers every snapshot evaluate with a canned pageScale, so the in-page scale logic and the pan guard at snapshot.ts:122 are never tested; and when the visual viewport is panned, the crop fails with the "published no capture scale or viewport" message at screenshot-crop-target.ts:206, while the README and website only mention a missing visualViewport.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 17, 2026
@alimek
alimek force-pushed the feat/tv-screenshot-crop branch from 1842881 to 82a054f Compare November 17, 2026 13:00
A Tizen or webOS TV enters as a provider-owned Android TV device, so
`screenshot --crop-on` fell into the android-device cell and was refused
before dispatch.

Give provider-owned Android TVs their own accepted crop cell, and keep
adb Android TVs, provider-owned TV emulators, and provider-owned phones
in their Android cells. The crop also requires the TV plugins' cdp-dom
page tree, the way a physical iPhone crop requires a CoreDevice capture.

A TV page's capture scale is not its devicePixelRatio. A webOS app at
1280x720 reports a ratio of 1.5 yet captures unscaled, while a Tizen
page with a 1280 meta viewport reports 1 and captures at 1.5x. Both
match visualViewport.scale, so the TV snapshot publishes it as
captureScale, together with its viewport. The crop scales rects by it
and clips them to the page, which fills only part of a webOS capture.
A TV page missing either cannot be cropped.
@alimek
alimek force-pushed the feat/tv-screenshot-crop branch from 82a054f to a20e4e3 Compare November 17, 2026 13:08
@alimek

alimek commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed a20e4e38f:

  • captureScale is now SnapshotCaptureScale: a branded positive finite number minted only by snapshotCaptureScaleFrom in @agent-device/kernel/rect, mirroring snapshotViewportSizeFrom. The tv-cdp producer, the contracts, the daemon and the projection take that type, and the local guard is gone. fr reports 0 findings on the touched files.
  • The in-page logic is tested now: tv-cdp/src/snapshot.test.ts evaluates SNAPSHOT_EXPRESSION in a node:vm page. It covers a published scale, a panned visual viewport, and a browser without visualViewport.
  • The refusal message and the TV docs now name the panned visual viewport too.

On the scale: yes. The fixture page prints its own innerWidth, devicePixelRatio and visualViewport.scale, and the target was located in each plain screenshot by its border pixels:

TV Page devicePixelRatio visualViewport.scale Capture
webOS 22 "resolution": "1280x720" 1.5 1 unscaled, 1 px per CSS px
Tizen 9.0 width=1280 meta viewport 1 1.5 1.5 px per CSS px
both native viewport 1 1 1 px per CSS px

That ran on the pre-rebase build. Since then the crop path changed only in this type and in how the rounding is written, which give the same numbers. The screenshots in the description show both captures.

@thymikee
thymikee merged commit 27a4e40 into callstack:main Nov 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants