Mac: Hide webview until loaded

This commit is contained in:
Chen-I Lim 2021-02-09 12:34:45 -08:00
parent 0fe96ad7ed
commit 13ca583e22

View file

@ -17,6 +17,7 @@ class ViewController:
webView.navigationDelegate = self
webView.uiDelegate = self
webView.isHidden = true
clearWebViewCache()
@ -154,8 +155,14 @@ class ViewController:
NSLog("webView didFinish navigation: \(webView.url?.absoluteString ?? "")")
// Disable right-click menu
webView.evaluateJavaScript("document.body.setAttribute('oncontextmenu', 'event.preventDefault();');", completionHandler: nil)
webView.isHidden = false
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
webView.isHidden = false
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if let frame = navigationAction.targetFrame,
frame.isMainFrame {