This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch pr-fix-regression-keep-uidelegate
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git

commit d296b3a569d114a22abb3dec63bd7a10b56c4414
Author: Manuel Beck <[email protected]>
AuthorDate: Thu Aug 6 13:48:10 2026 +0200

    fix(wkwebview): retain UIDelegate to restore alert/confirm/prompt
    
    - Fixes a regression introduced by #1664 where the property `uiDelegate` 
was removed from `CDVWebViewEngine`.
    - `WKWebView.UIDelegate` is weak, so the default `CDVWebViewUIDelegate` 
could be deallocated after assignment, which breaks JavaScript 
alert/confirm/prompt handling. Retain the delegate in `CDVWebViewEngine` by a 
strong property `uiDelegate` and clear it during dispose.
    - Add a regression test that verifies the web view engine keeps a non-nil 
uiDelegate.
    - Fixes #1684
---
 .../Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m       |  9 ++++++++-
 tests/CordovaLibTests/CDVWebViewEngineTests.swift             | 11 +++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m 
b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
index 250f2a9b..61b0a122 100644
--- a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
+++ b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
@@ -43,6 +43,9 @@
 @property (nonatomic, readwrite) NSString *CDV_ASSETS_URL;
 @property (nonatomic, readwrite) Boolean cdvIsFileScheme;
 @property (nullable, nonatomic, strong, readwrite) WKWebViewConfiguration 
*configuration;
+// WKWebView.UIDelegate is weak; retain the assigned delegate to keep
+// JavaScript alert/confirm/prompt callbacks available.
+@property (nonatomic, strong, readwrite) id <WKUIDelegate> uiDelegate;
 
 @end
 
@@ -278,7 +281,10 @@
         uiDelegate.mediaPermissionGrantType = [self 
parsePermissionGrantType:[settings 
cordovaSettingForKey:@"MediaPermissionGrantType"]];
         uiDelegate.allowNewWindows = [settings 
cordovaBoolSettingForKey:@"AllowNewWindows" defaultValue:NO];
 
-        wkWebView.UIDelegate = uiDelegate;
+        // WKWebView.UIDelegate is weak, so we must retain our default delegate
+        // to keep JavaScript alert/confirm/prompt handlers alive.
+        self.uiDelegate = uiDelegate;
+        wkWebView.UIDelegate = self.uiDelegate;
     }
 
     if ([self.viewController 
conformsToProtocol:@protocol(WKNavigationDelegate)]) {
@@ -301,6 +307,7 @@
 {
     WKWebView* wkWebView = (WKWebView*)_engineWebView;
     [wkWebView.configuration.userContentController 
removeScriptMessageHandlerForName:CDV_BRIDGE_NAME];
+    self.uiDelegate = nil;
     _engineWebView = nil;
 
     [super dispose];
diff --git a/tests/CordovaLibTests/CDVWebViewEngineTests.swift 
b/tests/CordovaLibTests/CDVWebViewEngineTests.swift
index 929acdaf..4a75c28d 100644
--- a/tests/CordovaLibTests/CDVWebViewEngineTests.swift
+++ b/tests/CordovaLibTests/CDVWebViewEngineTests.swift
@@ -38,6 +38,17 @@ class ScriptHandlingViewController: ViewController, 
WKScriptMessageHandler {
 }
 
 class CDVWebViewEngineTests: XCTestCase {
+    @MainActor func testWebViewUIDelegateIsRetained() {
+        let vc = ViewController()
+        vc.webContentFolderName = "www"
+        vc.startPage = "index.html"
+
+        vc.loadViewIfNeeded()
+
+        let uiDelegate = (vc.webViewEngine as AnyObject).value(forKey: 
"uiDelegate")
+        XCTAssertNotNil(uiDelegate)
+    }
+
     @MainActor func testViewControllerScriptMessageHandler() {
         let vc = ScriptHandlingViewController()
         vc.webContentFolderName = "www"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to