Skip to content

Add --width/--height/--device flags for mobile/responsive viewport emulation - #15

Open
josefrichter wants to merge 2 commits into
chrismccord:mainfrom
josefrichter:feature/mobile-viewport
Open

Add --width/--height/--device flags for mobile/responsive viewport emulation#15
josefrichter wants to merge 2 commits into
chrismccord:mainfrom
josefrichter:feature/mobile-viewport

Conversation

@josefrichter

@josefrichter josefrichter commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds viewport-size control so web can render responsive/mobile layouts. Passing a width makes CSS media queries (e.g. Tailwind's max-sm:/sm: breakpoints) fire as they would on that device — very useful for screenshotting and verifying responsive UIs.

Changes

  • --width <px> / --height <px> — set the viewport (height defaults to 900 when only width is given)
  • --device <name> — preset viewport size classes: mobile, tablet, desktop, wide, ultrawide (mobile and tablet also send a mobile user-agent)
  • Resizes the headless Firefox window before navigating. In headless mode the window size maps directly to the layout viewport, so no new dependencies are needed (ResizeWindow is already provided by the selenium lib).

Example:

web https://example.com --device mobile --screenshot mobile.png
web https://example.com --width 500 --screenshot mobile.png

Why size classes instead of device names

Headless Firefox enforces a minimum window width (~450px) at the Gecko widget layer, and Set Window Rect clamps anything below it. An earlier revision had per-device presets (iphone-se 375, iphone 390, pixel 412, iphone-max 430) — but the clamp meant all of them rendered at the same 450px viewport, differing only in height. Presets are now named by what the tool can actually deliver, and mobile declares the 450px floor directly (mobile breakpoints like matchMedia("(max-width: 639px)") still match). Explicit --width/--height remain for exact sizes above the floor.

Lets `web` render responsive/mobile layouts so CSS media queries
(e.g. Tailwind's max-sm:/sm: breakpoints) fire as they would on a
phone — useful for screenshotting and verifying responsive UIs.

- --width / --height set the viewport size (height defaults to 900)
- --device maps a preset name (iphone, iphone-se, iphone-max, pixel,
  ipad, desktop) to a viewport size + mobile user-agent
- Resizes the headless Firefox window before navigating; in headless
  mode the window size maps directly to the layout viewport
@josefrichter
josefrichter force-pushed the feature/mobile-viewport branch from 05fab95 to 807bd66 Compare July 1, 2026 15:20
… ultrawide)

Headless Firefox enforces a minimum window width (~450px) at the
Gecko widget layer, and the WebDriver Set Window Rect command clamps
anything below it. That made the per-device phone presets fiction:
iphone-se (375), iphone (390), pixel (412) and iphone-max (430) all
rendered at the same 450px viewport, differing only in height.

Name presets by what the tool can actually deliver — viewport size
classes — and have "mobile" declare the 450px floor directly instead
of requesting a width that silently clamps:

- mobile:    450x900  + mobile UA (Firefox floor; max-sm:/sm: fire)
- tablet:    820x1180 + mobile UA
- desktop:   1280x800
- wide:      1920x1080
- ultrawide: 2560x1440

Explicit --width/--height remain for exact sizes above the floor.
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.

1 participant