WKCookieWebView
WKCookieWebView copied to clipboard
Preload from `createWebViewWith`
Nice work!
Any suggestions on how to preload when creating a Web view dynamically, e.g. in response to window.open()
? I'm loading third-party content, so I don't know if/when the content wants to open another page.
public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
// Added an initializer to accept an existing configuration
let newWebView = WKCookieWebView(configuration: configuration)
if let url = navigationAction.request.url {
// Doesn't work, probably because we have to return the WebView synchronously,
// before we have a chance to preload. Loading later doesn't work.
WKCookieWebView.preloadWithDomainForCookieSync(urlString: url.absoluteString) {
newWebView.load(navigationAction.request)
}
}
// Add webview to tab list
myDelegate?.didOpenNewWebView(for: url)
return newWebView
}
Hi, I think the idea you suggested was a good idea. I'll try to figure out a way to apply it. Or you can do the PR yourself. ^^