Skip to content

feat(driver): emulate devices from Chrome DevTools with emulate: - #338

Merged
route merged 2 commits into
mainfrom
mobile-emulation
Oct 15, 2026
Merged

route merged 2 commits into
mainfrom
mobile-emulation

Conversation

@route

@route route commented Oct 15, 2026

Copy link
Copy Markdown
Member

Supersedes #292 (thanks @duncan-bayne, credited as co-author), closes #216.

Capybara::Cuprite::Driver.new(app, emulate: :iphone_14)
Capybara::Cuprite::Driver.new(app, emulate: :pixel_9, scale_factor: 1)
Capybara::Cuprite::Driver.new(app, mobile: true, window_size: [400, 800])
  • emulate: takes any of the 41 devices listed in Chrome DevTools' device toolbar (Capybara::Cuprite::Devices::LIST) and sets their window size, scale factor, mobile viewport with touch events, and user agent. Chrome/%<version>s in Android/Windows user agents is filled in with the running Chrome version, as DevTools does, and the user agent stays when other headers are set.
  • :mobile and :scale_factor also work as standalone options and take precedence over the device's values. They're applied in Page#set_viewport, so resize_window_to, maximize and fullscreen keep the emulation.
  • Bumps Ferrum to ~> 0.19.0, which enables touch emulation in Page#set_viewport(mobile: true).
  • Excludes lib/capybara/cuprite/devices.rb from Layout/LineLength and stops Naming/VariableNumber from checking symbols, so device names like :iphone_14 pass.

duncan-bayne and others added 2 commits October 15, 2026 19:51
Add `emulate:` driver option that takes a device listed in Chrome DevTools' device toolbar, e.g. `emulate: :iphone_14`,
and sets its window size, scale factor, mobile viewport with touch events and user agent. The Chrome version is filled
into the device user agent as DevTools does, and it stays when other headers are set.

`:mobile` and `:scale_factor` work on their own too and take precedence over the device's. They are applied in
`Page#set_viewport`, so they're kept across window resizes. Closes #216, supersedes #292.

Co-authored-by: Duncan Bayne <duncan@bayne.id.au>
@route route mentioned this pull request Oct 15, 2026
@route
route merged commit 86969bd into main Oct 15, 2026
7 checks passed
@route
route deleted the mobile-emulation branch October 15, 2026 17:36
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.

How to configure cuprite to test on mobile emulation ?

2 participants