Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload from createWebViewWith #7

Open
alekop opened this issue Sep 23, 2019 · 1 comment
Open

Preload from createWebViewWith #7

alekop opened this issue Sep 23, 2019 · 1 comment

Comments

@alekop
Copy link

alekop commented Sep 23, 2019

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
}
@Kofktu
Copy link
Owner

Kofktu commented Sep 25, 2019

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. ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants