Skip to content

fix: strip pre-PNG garbage from Android screenshots on multi-display devices#185

Merged
thymikee merged 3 commits intomainfrom
claude/fix-multi-display-screenshots-trejQ
Mar 4, 2026
Merged

fix: strip pre-PNG garbage from Android screenshots on multi-display devices#185
thymikee merged 3 commits intomainfrom
claude/fix-multi-display-screenshots-trejQ

Conversation

@thymikee
Copy link
Copy Markdown
Contributor

@thymikee thymikee commented Mar 4, 2026

Summary

  • On Android emulators with multiple displays (e.g. Galaxy Z Fold), adb exec-out screencap -p can write warning text to stdout before PNG bytes, producing corrupt screenshot files.
  • The screenshot path now finds the PNG signature and strips any leading bytes before it.
  • It now also parses PNG chunks and writes only through IEND, so trailing stdout garbage is stripped as well.
  • If no PNG signature is found, or the PNG payload is truncated, the command now fails with a clear error instead of writing invalid data.

Fixes #184

Validation

  • pnpm typecheck
  • node --test src/platforms/android/__tests__/snapshot.test.ts
  • Added/updated tests:
    • clean PNG output is written correctly
    • warning text before PNG signature is stripped
    • trailing garbage after PNG payload is stripped
    • missing PNG signature throws descriptive error
    • truncated PNG payload throws descriptive error
  • Manual (not run yet): boot Galaxy Z Fold emulator (dual display), run agent-device screenshot, verify valid PNG output

claude added 2 commits March 4, 2026 07:45
…devices

On Android emulators with multiple displays (e.g. Galaxy Z Fold), `adb
exec-out screencap -p` writes a warning to stdout before the PNG data,
producing corrupt files.  Locate the PNG signature in the buffer and
discard everything before it.

https://claude.ai/code/session_01Lfb3WKqXCSqYtCg8dbS8JW
- Remove unnecessary ternary; subarray(0) is a no-op
- Replace hex-encoded printf mock scripts with file-based payloads

https://claude.ai/code/session_01Lfb3WKqXCSqYtCg8dbS8JW
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 4, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://callstackincubator.github.io/agent-device/pr-preview/pr-185/

Built to branch gh-pages at 2026-03-04 08:24 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@thymikee thymikee merged commit 4df80af into main Mar 4, 2026
6 checks passed
@thymikee thymikee deleted the claude/fix-multi-display-screenshots-trejQ branch March 4, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screenshots corrupted on multi-display Android emulators (e.g. Galaxy Fold)

2 participants