         true
     }
 
-    @IBOutlet private var webView: WKWebView?
-
-    override func viewDidLoad() {
-        super.viewDidLoad()
-        navigationController?.interactivePopGestureRecognizer?.isEnabled = true
+    private lazy var webView: WKWebView = {
         let config = WKWebViewConfiguration()
         config.allowsInlineMediaPlayback = true
         config.mediaTypesRequiringUserActionForPlayback = []
         // adds: window.webkit.messageHandlers.xxxx.postMessage to JS env
         config.userContentController.add(self, name: "Native")
         config.userContentController.addUserScript(WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false))
-        webView = WKWebView(frame: view.bounds, configuration: config)
+        let webView = WKWebView(frame: view.bounds, configuration: config)
         // Alow rotation of webview
-        webView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
         // webView?.scrollView.isScrollEnabled = false
-        webView?.scrollView.bounces = false
-        webView?.navigationDelegate = self
+        webView.scrollView.bounces = false
+        webView.navigationDelegate = self
+        webView.uiDelegate = self
         // support dark mode and avoid white flashing when loading
-        webView?.isOpaque = false
-        webView?.backgroundColor = UIColor.clear
-        view.addSubview(webView!)
+        webView.isOpaque = false
+        webView.backgroundColor = UIColor.clear
+        return webView
+    }()
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        navigationController?.interactivePopGestureRecognizer?.isEnabled = true
+        view.addSubview(webView)
     }
 
     override func viewWillAppear(_ animated: Bool) {

        if let modifiedUrl = modifyUrl(orig: url) {
            let request = URLRequest(url: modifiedUrl)
            // clear out existing page while we load.
            webView?.evaluateJavaScript("document.body.remove()")
            webView?.load(request)
        }
    }


import UIKit
import WebKit

class OpenHABWebViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate {
    private var currentTarget = ""

    // https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?preferredLanguage=occ
