Repository navigation
chore: add a method and checks for retaking screenshots - #2843
claudiacodacy wants to merge 3 commits into
Conversation
Agents taking screenshots with Claude in Chrome have committed blank images before. screenshots.md sets the standard (a 1280x720 viewport at 100% zoom, saved as a 1456x819 PNG, no pointer) and the steps. finish-screenshot.py checks zoom and viewport, removes the pointer and records how the image was made. validate-screenshot.py rejects blank, JPEG, blurry, pixelated and wrong-size images and checks expected text with macOS Vision. hide-ui.py and the validator read a git-ignored local list of UI that customers don't see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 73 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
Two blocking risks remain: fixed-position account-specific elements can be missed by the hiding check, and the finishing algorithm can mistake unrelated small changes for pointer differences. These leave acceptance criteria around UI removal and pointer-only merging only partially implemented.
The screenshot validator also does not reliably reject partially transparent images. The affected image-processing scripts are complex and lack automated coverage for their failure paths.
Codacy also found:
- 45 complexity points in
.claude/scripts/validate-screenshot.pyand 28 in.claude/scripts/finish-screenshot.py. - Shebang/executable-bit consistency findings in
.claude/scripts/hide-ui.pyand.claude/scripts/validate-screenshot.py.
Test suggestions
- Finish two valid full-page captures with pointers in different locations and verify the output removes both pointers without changing other pixels.
- Reject finishing when the page has the wrong device pixel ratio, viewport, capture dimensions, or capture count.
- Reject capture pairs that differ in content beyond pointer-sized regions.
- Validate rejection of blank, near-blank, blurry, pixelated, JPEG-derived, incorrectly sized, and incorrectly stamped images.
- Validate OCR expectations and hidden-list text or line rejection, including allowed lines.
- Generate the hide script from a local configuration and report hidden and still-visible selectors.
- Exercise malformed-image and OCR-failure paths in the validator.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Finish two valid full-page captures with pointers in different locations and verify the output removes both pointers without changing other pixels.
2. Reject finishing when the page has the wrong device pixel ratio, viewport, capture dimensions, or capture count.
3. Reject capture pairs that differ in content beyond pointer-sized regions.
4. Validate rejection of blank, near-blank, blurry, pixelated, JPEG-derived, incorrectly sized, and incorrectly stamped images.
5. Validate OCR expectations and hidden-list text or line rejection, including allowed lines.
6. Generate the hide script from a local configuration and report hidden and still-visible selectors.
7. Exercise malformed-image and OCR-failure paths in the validator.
TIP Add a Jira or Linear ticket key to the branch or title so the reviewer can check the PR against it. Using another tracker? Tell us.
TIP How was this review? Give us feedback
| } | ||
| const stillVisible = (config.check || []).flatMap((selector) => | ||
| [...document.querySelectorAll(selector)] | ||
| .filter((element) => element.offsetParent) |
There was a problem hiding this comment.
🔴 HIGH RISK
Visible fixed-position elements are omitted from stillVisible because their offsetParent is null. This can allow account-only UI into screenshots when hiding it fails. Consider checking computed visibility and rendered bounds instead.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| alpha_mean = ImageStat.Stat(image.getchannel("A")).mean[0] | ||
| if alpha_mean < 250: | ||
| failures.append(f"partly transparent: mean alpha {alpha_mean:.0f} of 255") |
There was a problem hiding this comment.
🟡 MEDIUM RISK
The validator does not reliably reject partly transparent PNGs because it checks only mean alpha; inspect whether any alpha value is below 255 (or apply an explicitly documented tolerance) so transparent pixels cannot pass unnoticed.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| boxes = regions(differs) | ||
| too_big = [b for b in boxes if b[2] - b[0] > MAX_POINTER_SIZE or b[3] - b[1] > MAX_POINTER_SIZE] | ||
| if len(boxes) != 2 or too_big: |
There was a problem hiding this comment.
🟡 MEDIUM RISK
If the pointer fails to move but two small UI regions change between captures, this accepts those changes as pointers and leaves the actual pointer in the output. Consider requiring the pointer positions and rejecting differences outside those regions.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| probe.verify() | ||
| image = Image.open(path) | ||
| image.load() | ||
| except Exception as error: # a truncated or corrupt file |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Unexpected programming errors during image validation can be swallowed and reported as corrupt-image failures because this catches every Exception. Catch the specific Pillow exceptions expected from verify(), load(), and decoding instead.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Return to Previous Size is greyed out when a window is tiled to a corner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agents retaking product screenshots with Claude in Chrome have committed images that looked right in the transcript but weren't: one was a blank white PNG. This adds a standard, the steps, and checks that must pass before an image is committed. Replaces #2841.
The standard
Changes
.claude/reference/screenshots.md: the standard, the Claude in Chrome steps, and the methods that don't work and why..claude/scripts/finish-screenshot.py: takes the page check (innerWidth,innerHeight,devicePixelRatio) and two captures. Refuses any other zoom, viewport or capture size, removes the pointer Claude in Chrome draws (refusing if anything else changed between captures), and writes a capture record into the PNG..claude/scripts/validate-screenshot.py: fails if the file isn't a real PNG, has no capture record or the wrong one, isn't 1456×819 (or, with--crop, is under 400×150), is blank or nearly one colour, is partly transparent, is blurry or scaled up, is pixelated, went through JPEG, shows text from the local hide list, or doesn't contain the--expecttext. Text is read with macOS Vision (ocr.swift)..claude/scripts/hide-ui.py: prints a page script that hides the elements in the local hide list and reports any that are still visible..gitignore: ignores.claude/screenshots.local.json, the local hide list.CLAUDE.md: links the new reference.How it was tested
finish-screenshot.pyrefuses a window at 80% zoom, a wrong viewport and captures of the wrong size. On a matching pair it removes both pointers and changes no other pixel.🚧 To do
🤖 Generated with Claude Code