WKWebKit browser not loading website (macOS)

31 Views Asked by At

I can't seem to get a website to load on my macOS web browser app. This is the code am using:

        @IBOutlet weak var web: WKWebView! 

        let purl = URL(string: "https://www.google.com")!

        web.load(URLRequest(url: purl))

        web.allowsBackForwardNavigationGestures = true
1

There are 1 best solutions below

0
Mostafa Shamin Yeasar On

I think this will do:

class ViewController: NSViewController, WKUIDelegate,  WKNavigationDelegate {
      @IBOutlet weak var web: WKWebView! 
      override func viewDidLoad() {
                super.viewDidLoad()
                web.navigationDelegate = self //The thing you were missing, I guess
        }
      override func viewDidAppear() {
        super.viewDidAppear()
        let purl = URL(string: "https://www.google.com")!

                web.load(URLRequest(url: purl))

                web.allowsBackForwardNavigationGestures = true
        }
}