Skip to content

feat: return errors for missing/zero-dimension elements in selector screenshots#942

Open
mvanhorn wants to merge 1 commit intovercel-labs:mainfrom
mvanhorn:osc/587-element-screenshot-error-handling
Open

feat: return errors for missing/zero-dimension elements in selector screenshots#942
mvanhorn wants to merge 1 commit intovercel-labs:mainfrom
mvanhorn:osc/587-element-screenshot-error-handling

Conversation

@mvanhorn
Copy link
Contributor

Summary

When screenshot @ref output.png targets an element that can't be found or has zero dimensions, return a clear error instead of silently falling back to a full-page screenshot.

Changes

In cli/src/native/screenshot.rs, the selector branch now uses a match instead of if let Some:

  • None from get_rect_for_selector returns: "Element '{selector}' not found or not visible on the page"
  • Zero or negative width/height returns: "Element '{selector}' has zero dimensions ({width}x{height})"
  • Full-page and viewport screenshot behavior unchanged

Why this matters

The element screenshot clipping already works correctly when the element is found (screenshot.rs:202-218). The gap is that a missing element silently produces a full-page screenshot, which is confusing in automation pipelines where you expect either the element's screenshot or an error.

#587 - 5 reactions, highest of any open feature request.

Testing

  • screenshot output.png - full page (unchanged)
  • screenshot @e3 element.png - captures element bounding box (unchanged, already worked)
  • screenshot @nonexistent out.png - now returns error instead of full-page fallback

Closes #587

This contribution was developed with AI assistance (Claude Code).

…creenshots

When `screenshot @ref output.png` targets an element that can't be found
or has zero dimensions, return a clear error instead of silently falling
back to a full-page screenshot.

Closes vercel-labs#587
@vercel
Copy link
Contributor

vercel bot commented Mar 20, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Feature] Support Element Screenshot

1 participant