maestro icon indicating copy to clipboard operation
maestro copied to clipboard

Fix WebView element access on iOS 26 by including SafariViewService hierarchy

Open leovarmak opened this issue 1 month ago • 2 comments

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 snapshotMaxDepth limit 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.

leovarmak avatar Dec 04 '25 13:12 leovarmak

Rebased.

Fishbowler avatar Dec 12 '25 13:12 Fishbowler

Sorry for all of the noise 😬

Fishbowler avatar Dec 19 '25 14:12 Fishbowler