Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.

Add screenshot support#6

Merged
4fuu merged 3 commits into
mainfrom
feature/screenshot
Mar 28, 2026
Merged

Add screenshot support#6
4fuu merged 3 commits into
mainfrom
feature/screenshot

Conversation

@4fuu
Copy link
Copy Markdown
Owner

@4fuu 4fuu commented Mar 28, 2026

Summary

  • Adds browser-cli screenshot <session-id> command with --output, --full-page, --quality, and --json options
  • Extension captures the visible tab viewport via chrome.tabs.captureVisibleTab() and returns base64-encoded image data
  • CLI decodes the base64 image and writes it to disk (default filename: screenshot-<timestamp>.png)
  • Adds base64 = "0.22" dependency, activeTab permission in manifest, and screenshot action constant in the protocol

Notes

  • --full-page is accepted but prints a warning and falls back to viewport capture (full-page stitching can be added later)
  • When --quality is specified, the image format switches from PNG to JPEG
  • The screenshot action is not cached by the relay (passes through to the extension directly)

Test plan

  • Run browser-cli screenshot <session-id> and verify a PNG file is saved
  • Run with --output custom.png and verify the custom path is used
  • Run with --quality 80 and verify a JPEG file is produced
  • Run with --json and verify structured JSON output
  • Run with --full-page and verify the warning is printed
  • Verify the extension loads without errors with the updated manifest permissions

Closes #4

Mule added 2 commits March 28, 2026 15:28
Implements the `browser-cli screenshot <session-id>` command with
`--output`, `--full-page`, and `--quality` options. The extension
uses `chrome.tabs.captureVisibleTab()` to capture the viewport and
returns base64-encoded image data. The CLI decodes and writes the
image to disk. Full-page capture is accepted but prints a warning
as it is not yet implemented.

Closes #4
…ed parameter type

Use `Parameters<typeof chrome.tabs.captureVisibleTab>[1]` instead of
the non-existent `chrome.tabs.CaptureVisibleTabOptions` type.
@4fuu
Copy link
Copy Markdown
Owner Author

4fuu commented Mar 28, 2026

@codex review this pr

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 984dfd5daa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

// Ensure the tab is active in its window before capturing
await chrome.tabs.update(session.value.tab_id, { active: true });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore active tab after taking a screenshot

handleScreenshot force-activates the target tab (chrome.tabs.update(..., { active: true })) but never restores the previously active tab in that window. When a screenshot is taken for a background session, this permanently steals focus and changes browser state for the user, which is an unexpected side effect of a read-only command and can disrupt ongoing work in other tabs.

Useful? React with 👍 / 👎.

Comment thread src/main.rs
Comment on lines +289 to +291
/// Image quality for JPEG (0-100, default: PNG format)
#[arg(long)]
quality: Option<u32>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Enforce documented --quality bounds at parse time

The CLI help text documents --quality as 0-100, but the argument is parsed as unconstrained Option<u32>, so values like --quality 500 are accepted and forwarded. That creates a contract mismatch and pushes invalid/undefined quality handling into the extension/API layer; adding a clap range constraint here would make behavior deterministic and fail fast with a clear error.

Useful? React with 👍 / 👎.

@4fuu 4fuu merged commit 80ac59f into main Mar 28, 2026
2 checks passed
@4fuu 4fuu deleted the feature/screenshot branch March 28, 2026 16:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add screenshot support

1 participant