Skip to content

Add viewport + deviceScaleFactor to config schema #1356

@MariusWilsch

Description

@MariusWilsch

Summary

Add viewport and deviceScaleFactor config fields to agent-browser.json / ~/.agent-browser/config.json so a pinned viewport+DPR survives daemon restarts.

Motivation

The runtime command agent-browser set viewport <w> <h> [scale] works perfectly for pinning dimensions + DPR. But there's no persistent equivalent in the config file — every config key from the Configuration docs is enumerated and viewport/DPR is not among them.

This forces a per-session ritual: call set viewport W H 1 at the start of every workflow before any screenshot, or accept whatever the daemon's CDP defaults produce.

On macOS Retina (DPR=2) with --start-maximized in args (for a comfortable headed-mode window), screenshots come out at physical-pixel dimensions — e.g. screenshot at innerWidth 1920 × innerHeight 1057 produces 3840 × 2114 px PNG files. These are accurate but reviewer-hostile when committed to a Git host (GitHub blob view, etc.) and scrolled at 1:1 zoom.

Why config.json args doesn't work

args: "--start-maximized --force-device-scale-factor=1" has no effect on DPR. The daemon appears to call CDP Emulation.setDeviceMetricsOverride after launch and clobbers whatever Chrome was launched with. Tested with daemon restart on agent-browser 0.27.0, macOS Retina:

$ jq '.args' ~/.agent-browser/config.json
"--start-maximized --force-device-scale-factor=1"

$ agent-browser eval "({iw:innerWidth, ih:innerHeight, dpr:devicePixelRatio})"
{ "iw": 1920, "ih": 1057, "dpr": 2 }   # DPR still 2

$ agent-browser screenshot /tmp/test.png && sips -g pixelWidth -g pixelHeight /tmp/test.png
pixelWidth: 3840
pixelHeight: 2114

Compared with runtime override that does work:

$ agent-browser set viewport 1920 1080 1
$ agent-browser eval "({iw:innerWidth, ih:innerHeight, dpr:devicePixelRatio})"
{ "iw": 1920, "ih": 1080, "dpr": 1 }   # DPR pinned

$ agent-browser screenshot /tmp/test.png && sips -g pixelWidth -g pixelHeight /tmp/test.png
pixelWidth: 1920
pixelHeight: 1080

Proposed config keys

{
  "viewport": { "width": 1920, "height": 1080 },
  "deviceScaleFactor": 1
}

Or as a flat shorthand (matching CLI set viewport <w> <h> [scale]):

{
  "viewport": "1920x1080@1"
}

Either shape applied at daemon-start via the same CDP path the runtime command uses (Emulation.setDeviceMetricsOverride).

Use cases

  • Reviewer-friendly screenshots committed to a repo: pin to 1280×800 or 1920×1080 DPR=1 so blob-view zoom is 1:1 with no compression
  • Witness/QA ceremonies where evidence images need deterministic dimensions across sessions
  • CI environments where each spawned daemon should produce comparable screenshots
  • Workaround today: bash function wrapping agent-browser that runs set viewport after open — works but every operator has to add it

Environment

  • agent-browser 0.27.0 (latest)
  • macOS 24.3.0, Retina display
  • Chrome via daemon, headed: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions