maestro
maestro copied to clipboard
Fix WebView element access on iOS 26 by including SafariViewService hierarchy
Summary
Fixes #2735
On iOS 26, SFSafariViewController and similar WebViews run in a separate application container (com.apple.SafariViewService) rather than within the host app's process. This causes Maestro to miss all WebView elements when capturing the view hierarchy.
Changes
Added getSafariWebViewHierarchy() helper in ViewHierarchyHandler.swift that:
- Detects iOS 26+ and checks if SafariViewService is running with active webviews
- Fetches the Safari WebView hierarchy and merges it into the main view hierarchy response
- Applies the existing
snapshotMaxDepthlimit to prevent memory issues with complex web pages
Safeguards
Based on feedback from earlier attempts (crashes on M1 CI machines), this implementation includes:
- iOS version gating (only runs on iOS 26+)
- Pre-checks for service state and webview presence before attempting snapshot
- Depth limiting via
AXClientSwizzler - Graceful error handling - returns nil instead of crashing if snapshot fails
Testing
- Tested on iOS 26 simulator with apps using
SFSafariViewController. WebView elements are now visible in Maestro Studio and accessible for automation. - Tested on iOS 18 simulator. WebView elements are now visible in Maestro Studio and accessible for automation.
Rebased.
Sorry for all of the noise 😬