JavaScript Not Executing in WebView When Modally Presenting UIViewController on iOS 17.5.1

Issue Summary:

I have encountered an issue where JavaScript does not execute in a WebView when another UIViewController is presented modally with modalPresentationStyle.fullScreen. This problem only occurs on physical devices running iOS 17.5.1. The issue is not present on iOS 17.5 simulators or devices running iOS 17.4.1 or earlier.

Reproduction Steps:

  1. Create a ViewController with a WebView.
  2. Load a web page (e.g., https://apple.com) in the WebView.
  3. Present another ViewController modally with modalPresentationStyle.fullScreen.
  4. Verify that JavaScript execution in the initial WebView stops working.

Test Code:

import UIKit
import WebKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Set up the WebView
        let configuration = WKWebViewConfiguration()
        let webView = WKWebView(frame: view.frame, configuration: configuration)
        view.addSubview(webView)
        webView.frame = view.frame
        if #available(iOS 16.4, *) {
            webView.isInspectable = true
        } else {
            // Fallback on earlier versions
        }
        webView.load(URLRequest(url: URL(string: "https://apple.com")!))
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        let navigationController = UINavigationController(rootViewController: TargetViewController())
        navigationController.modalPresentationStyle = .fullScreen
        present(navigationController, animated: true)
    }
}

class TargetViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Set up the WebView
        let webView = WKWebView(frame: view.frame, configuration: WKWebViewConfiguration())
        view.addSubview(webView)
        webView.frame = view.frame
        
        if #available(iOS 16.4, *) {
            webView.isInspectable = true
        } else {
            // Fallback on earlier versions
        }
        webView.load(URLRequest(url: URL(string: "https://apple.com")!))
    }
}

Observations:

  • The JavaScript within the WebView stops executing only on physical devices running iOS 17.5.1.
  • This issue does not occur on the iOS 17.5 simulator.
  • Devices running iOS 17.4.1 or earlier do not experience this issue.

Request for Assistance:

Could you please provide any insights or potential workarounds for this issue? Additionally, if this is a known bug, any information on upcoming fixes would be highly appreciated.

Thank you.

Thank you for the clear report. Please file an issue using Feedback Assistant, and, if you can, attach a small test app that demonstrates the problem, which will help us investigate.

Hello,

Is there any solution for this topic, i have similar problem with camera, if it is opened in fullscreen.

„Same Version iOS 17.5.1“

I am looking forward to your reply

@mqz I have the same problem, how can I fix it?

JavaScript Not Executing in WebView When Modally Presenting UIViewController on iOS 17.5.1
 
 
Q