jQuery modal dialog popup not showing in WKWebView

Hi, I have a WKWebview to open the client's website. In the website, there is a "Cancel" button that will open a popup for confirmation. In Safari or other web clients, it works and it will open a popup. But in my iOS app, it didn't. When I ask the web FE developer, he said that he is using jQuery modal dialog for the popup. I tried using this, but doesn't work:

class WebsiteViewController: UIViewController {
    var urlRequest: URLRequest?

    @IBOutlet weak private var ibWebView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        ibWebView.configuration.websiteDataStore = .nonPersistent()
        ibWebView.configuration.preferences.javaScriptEnabled = true
        ibWebView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
        ibWebView.navigationDelegate = self
        ibWebView.uiDelegate = self

        loadInternetBanking()

     }

    private func loadInternetBanking() {
        guard let urlRequest = urlRequest else {
            return
        }
        ibWebView.load(urlRequest)
    }
}

extension InternetBankingViewController: WKUIDelegate {
    func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        print(":::::::: createWebViewWith!!!!") //- this doesn't get called
        let popupWebView = WKWebView(frame: view.bounds, configuration: configuration)
        popupWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        return popupWebView
    }
    
    func webViewDidClose(_ webView: WKWebView) {
        
    }

    func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo) async {
        print(":::::::: runJavaScriptAlertPanelWithMessage!!!!") //- this doesn't get called
    }

    func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo) async -> Bool {
        print(":::::::: runJavaScriptConfirmPanelWithMessage!!!!") //- this doesn't get called

        return true
    }
}

The createWebViewWith, runJavaScriptAlertPanelWithMessage, and runJavaScriptConfirmPanelWithMessage callbacks are not being called. Can you help me with this?

Thank you.

Replies

ibWebView.uiDelegate = self ---> self is WebsiteViewController which doesn't implement WKUIDelegate

extension InternetBankingViewController: WKUIDelegate. -----> InternetBankingViewController implements the delegate but you are not using InternetBankingViewController