Open javascript popup in WKWebView?

I have a WKWebView in my app which opens a page where there is a button that uses javascript to open another page with window.open().
Now it's seems that webView(navigationAction) is never called when tapping this button. I have managed to get target="_blank" links to open, but I don't understand how I can get window.open() to work?
I have added a uiDelegate to create popup windows like this:

Code Block swift
public class WKWebVC: UIViewController {
...
override public func viewDidLoad() {
super.viewDidLoad()
webView.navigationDelegate = self
webView.uiDelegate = self
webView.configuration.preferences.javaScriptEnabled = true
   webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
...

and then the extension for WKWebVC:
Code Block swift
extension WKWebVC: WKUIDelegate {
  private func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
    debugPrint("(👉🏽👉🏽👉🏽 createWebViewWith")
    popupWebView = WKWebView(frame: view.bounds, configuration: configuration)
    popupWebView!.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    popupWebView!.navigationDelegate = self
    popupWebView!.uiDelegate = self
    view.addSubview(popupWebView!)
    return popupWebView!
  }
  private func webViewDidClose(_ webView: WKWebView) {
    if webView == popupWebView {
      popupWebView?.removeFromSuperview()
      popupWebView = nil
    }
  }
}

But createWebViewWith is never called either...
I was facing the same issue... You need to add the javaScriptCanOpenWindowsAutomatically = true to the WKPreference object in the WKWebview's Configuration... This will cause the createWebViewWith delegate to be called...

Code Block
let wkPreferences = WKPreferences()
wkPreferences.javaScriptCanOpenWindowsAutomatically = true

Build the Configuration of the WKWebView object
Code Block
    let configuration = WKWebViewConfiguration()
    configuration.preferences = wkPreferences

Naturally use the configuration object when creating the WKWebView
Code Block
webView = WKWebView(frame: .zero, configuration: configuration)

Answer here does not work - javaScriptCanOpenWindowsAutomatically does nothing. iOS is pain. Everything what works on Android is problematic on iOS. Android WebView has no problem with window.open(). We needed to open link with PDF and link is dynamically created. We had to change "button" element with onclick="window.open(...)" to "a" element with target=_blank and dynamic href=...

Open javascript popup in WKWebView?
 
 
Q