 				webView.isHidden = false
 			}
 		}
+	}
+
+	// WKUIDelegate
+	
+	func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
+		// This method is reached when WebKit handles a JavaScript based window.open() invocation, for example. One
+		// example where this is used is in YouTube's embedded video player when a user clicks on the video's title
+		// or on the "Watch in YouTube" button. For our purposes we'll handle such window.open calls the same way we
+		// handle clicks on a URL.
+		if let url = navigationAction.request.url {
+			self.openInBrowser(url, flags: navigationAction.modifierFlags)
+		}
+
+		return nil
 	}
 }
 

	}
}

// MARK: - WKNavigationDelegate

extension DetailWebViewController: WKNavigationDelegate {

	public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
		if navigationAction.navigationType == .linkActivated {
			if let url = navigationAction.request.url {
				let flags = navigationAction.modifierFlags
				let invert = flags.contains(.shift) || flags.contains(.command)
				Browser.open(url.absoluteString, invertPreference: invert)
			}
			decisionHandler(.cancel)
			return

	func mouseDidExit(_: DetailWebViewController)
}

final class DetailWebViewController: NSViewController {

	weak var delegate: DetailWebViewControllerDelegate?
	var webView: DetailWebView!
