Skip to content

fix: detect iOS screen scale factor dynamically instead of hardcoding 3x#363

Open
haosenwang1018 wants to merge 2 commits intozai-org:mainfrom
haosenwang1018:fix/ios-dynamic-scale-factor
Open

fix: detect iOS screen scale factor dynamically instead of hardcoding 3x#363
haosenwang1018 wants to merge 2 commits intozai-org:mainfrom
haosenwang1018:fix/ios-dynamic-scale-factor

Conversation

@haosenwang1018
Copy link

Problem

The iOS device module hardcodes SCALE_FACTOR = 3 to convert pixel coordinates to WDA point coordinates. This produces incorrect tap/swipe positions on non-3x devices (e.g. iPhone SE at 2x, older iPads at 2x).

Relates to #311 (iOS coordinate calculation inaccuracy).

Solution

Replace the constant with a _detect_scale_factor() function that:

  1. Queries WDA /window/size to get the screen width in points
  2. Takes a screenshot to get the width in pixels
  3. Divides pixel width by point width to derive the actual scale factor
  4. Validates the result against known iOS scales (1x, 2x, 3x)
  5. Caches the result per WDA URL to avoid repeated queries
  6. Falls back to 3 if detection fails (preserves current behavior for most users)

All touch functions (tap, double_tap, long_press, swipe) now use the dynamically detected factor.

A public get_scale_factor() accessor is also exposed for external use.

Testing

  • On 3x devices: behavior is unchanged (detected factor = 3.0, same as before)
  • On 2x devices: coordinates are now correctly halved instead of thirded

Replace the hardcoded SCALE_FACTOR = 3 with runtime detection that
compares screenshot pixel dimensions against WDA's reported window
size in points. The detected value is cached per WDA URL to avoid
repeated queries.

This fixes incorrect tap/swipe coordinates on non-3x devices such as
iPhone SE (2x) and older iPads.

Closes zai-org#311
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