feat(browse): add device emulation presets#361
Open
mvanhorn wants to merge 2 commits intogarrytan:mainfrom
Open
feat(browse): add device emulation presets#361mvanhorn wants to merge 2 commits intogarrytan:mainfrom
mvanhorn wants to merge 2 commits intogarrytan:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
devicecommand 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 upgradesresponsiveto use real device profiles instead of plain viewport resizes.Why this matters
The
responsivecommand 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
devicetoWRITE_COMMANDSincommands.tsactiveDevicestate +setDevice()/getDevice()toBrowserManagerlaunch(),recreateContext(), handoffdevice <name>applies full profile,device listshows 143 profiles,device clearresetsresponsivenow uses iPhone 15 Pro for mobile and iPad gen 7 for tablet instead of plain viewport resizesDemo
Before / After
Desktop (1280x720, default Chrome UA):
iPhone 15 Pro (393x659, mobile Safari UA, DPR 3, touch enabled):
HN reflowed to mobile layout because the UA and viewport now match a real iPhone.
Testing
bun testpasses (pre-existing test-2 failure in eval-store is unrelated, confirmed on main)deviceset/list/clear, fuzzy match errors,responsivewith device profilesThis contribution was developed with AI assistance (Claude Code).