Skip to content

Add rodney viewport command for viewport and mobile emulation#40

Open
johnwards wants to merge 2 commits into
simonw:mainfrom
johnwards:viewport-command
Open

Add rodney viewport command for viewport and mobile emulation#40
johnwards wants to merge 2 commits into
simonw:mainfrom
johnwards:viewport-command

Conversation

@johnwards
Copy link
Copy Markdown

@johnwards johnwards commented Feb 28, 2026

Summary

  • Adds a new rodney viewport <width> <height> [--scale N] [--mobile] command that sets the browser viewport size via Chrome's EmulationSetDeviceMetricsOverride CDP call
  • Adds rodney viewport --reset to clear the override and restore browser defaults (EmulationClearDeviceMetricsOverride)
  • Adds --viewport WxH, --mobile, and --scale N flags to rodney start for configuring viewport at launch time
  • Viewport settings are persisted in state.json and re-applied on each subsequent command, consistent with rodney's ephemeral-process architecture
  • rodney screenshot now respects the active viewport by default instead of always overriding to 1280x720 — pass -w/-h to explicitly override

Bug fix

Also fixes a pre-existing bug where rodney start --show would hit the default: fatal("unknown flag: ...") case in the flag-parsing loop before the --show flag was checked in a separate loop below. All start flags are now parsed in a single pass.

Usage examples

# Set mobile viewport
rodney viewport 375 812 --mobile --scale 2

# Reset to browser default
rodney viewport --reset

# Start with viewport pre-configured
rodney start --viewport 375x812 --mobile --scale 2

# Screenshots now respect the active viewport
rodney viewport 375 812 --mobile --scale 2
rodney screenshot mobile.png    # Uses 375x812 viewport
rodney screenshot -w 1280       # Explicitly override to 1280

Test plan

  • Unit tests for formatViewportDesc (basic, mobile, scale, combined, omission of scale 1/0)
  • State serialization round-trip test (json.Marshal / Unmarshal)
  • omitempty verification — zero-value viewport fields excluded from JSON
  • End-to-end CDP test — EmulationSetDeviceMetricsOverride sets innerWidth and devicePixelRatio
  • End-to-end CDP test — EmulationClearDeviceMetricsOverride restores defaults
  • Reset clears persisted state fields
  • Screenshot skips default viewport override when viewport is active
  • go build passes
  • All existing tests continue to pass

🤖 Generated with Claude Code

Adds viewport/mobile emulation via Chrome's EmulationSetDeviceMetricsOverride CDP call:

- `rodney viewport <w> <h> [--scale N] [--mobile]` — set viewport size
- `rodney viewport --reset` — restore browser defaults
- `rodney start --viewport WxH [--mobile] [--scale N]` — configure viewport at launch

Viewport settings are persisted in state.json and re-applied on each subsequent
command, matching rodney's ephemeral-process architecture.

Also fixes a pre-existing bug where `rodney start --show` would hit the unknown
flag error before reaching the headless flag parser. All start flags are now
parsed in a single pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Previously, `rodney screenshot` always overrode the viewport to 1280x720
(scale 1), clobbering any viewport set via `rodney viewport`. Now it only
applies its default viewport when no viewport override is active or when
-w/-h are explicitly passed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@johnwards johnwards closed this Feb 28, 2026
@johnwards johnwards reopened this Feb 28, 2026
@matthewbjones
Copy link
Copy Markdown

Related to older PR #33

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.

2 participants