Skip to content

feat(browse): add device emulation presets#361

Open
mvanhorn wants to merge 2 commits intogarrytan:mainfrom
mvanhorn:osc/feat-device-emulation-presets
Open

feat(browse): add device emulation presets#361
mvanhorn wants to merge 2 commits intogarrytan:mainfrom
mvanhorn:osc/feat-device-emulation-presets

Conversation

@mvanhorn
Copy link
Contributor

@mvanhorn mvanhorn commented Mar 23, 2026

Summary

Adds a device command to browse that applies Playwright's built-in device profiles. 143 devices available. Sets viewport, user-agent, DPR, touch, and isMobile in one command. Also upgrades responsive to use real device profiles instead of plain viewport resizes.

Why this matters

The responsive command resizes viewport to 3 hardcoded breakpoints but keeps the desktop Chrome user-agent. Sites that serve different content based on UA string show desktop layouts in "mobile" screenshots. Real device testing needs matching UA, DPR, touch capability, and isMobile flag.

This is listed in TODOS.md as "Device emulation presets" (P4, effort S) and noted as an intentional gap in ARCHITECTURE.md.

Changes

  • Add device to WRITE_COMMANDS in commands.ts
  • Add activeDevice state + setDevice()/getDevice() to BrowserManager
  • Device properties propagate through all context creation paths: launch(), recreateContext(), handoff
  • device <name> applies full profile, device list shows 143 profiles, device clear resets
  • Fuzzy-matches device names on typo with "Did you mean?" suggestion
  • responsive now uses iPhone 15 Pro for mobile and iPad gen 7 for tablet instead of plain viewport resizes

Demo

\$ browse device iPhone 15 Pro
Device: iPhone 15 Pro
  Viewport: 393x659
  DPR: 3
  Mobile: true
  Touch: true
  UA: Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHT...

\$ browse device list | head -10
143 devices available:
Blackberry PlayBook
Blackberry PlayBook landscape
BlackBerry Z30
...

\$ browse device clear
Device profile cleared. Using default viewport (1280x720).

\$ browse device iphone
Device "iphone" not found. Did you mean "iPhone 6"?

Before / After

Desktop (1280x720, default Chrome UA):

Desktop

iPhone 15 Pro (393x659, mobile Safari UA, DPR 3, touch enabled):

iPhone 15 Pro

HN reflowed to mobile layout because the UA and viewport now match a real iPhone.

Testing

  • bun test passes (pre-existing test-2 failure in eval-store is unrelated, confirmed on main)
  • Manually tested: device set/list/clear, fuzzy match errors, responsive with device profiles
  • SKILL.md regenerated for both Claude and Codex hosts

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

mvanhorn and others added 2 commits March 22, 2026 23:27
Add `device` command that applies Playwright's built-in device profiles
(143 devices). Sets viewport, user-agent, DPR, isMobile, and hasTouch
in one command. Supports `device list` to show profiles and `device clear`
to reset. Fuzzy-matches device names on typo.

Update `responsive` command to use full device profiles (iPhone 15 Pro
for mobile, iPad gen 7 for tablet) instead of plain viewport resizes,
so screenshots get correct user-agent and touch emulation.

Device properties now propagate through all context creation paths:
launch(), recreateContext(), and handoff().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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