Giter Club home page Giter Club logo

wkcookiewebview's Issues

Missing cookie values in iOS 10 or lower

Hi,
First of all, thank you for making this library. I'm currently migrating a project to WKWebView and this solved my issue of retaining the login session when opening another WKWebView. However, I encountered a bug where some cookie values were missing in iOS 10 or lower.

Usecase:

  • When client has logged in, check the session key from cookies and store it locally.
  • Check session key and preload it every time the app is opened.

In my case, I need to have a record of all the cookies retrieved by WKCookieWebView and get the session key from there.

I managed to solve this and I would like to file a PR.

When redirect with 302, WKCookieWebView not save cookies.

I sent request to 1stURL, 1stURL will redirect to 2ndURL with "Set Cookie" in response header, but the cookie is not set.
With httpCookieStore for WKWebsiteDataStore in iOS 11 can I retrieve the cookie, but with a previous version of ios?

onUpdateCookieStorage called with not actual cookies

When onUpdateCookieStorage event happened i will call:
HTTPCookieStorage.shared.cookies?.forEach { cookie in
...
}

But cookie has old values. Only when i call:
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
HTTPCookieStorage.shared.cookies?.forEach { cookie in
...
}
}
I will receive actual cookies. What i do wrong? How can i wait for actual cookies

But when i call it after 1 second it's not enough :(

쿠키가 저장이 안되는 것 같습니다.

print("=====================Cookies=====================")
HTTPCookieStorage.shared.cookies?.forEach {
print($0)
}
print("=================================================")

사이에 어떤 cookie도 저장되어 출력이 안되는 것 같아서 문의 남겨요!

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
}

Javascript for setting cookie is working incorrectly

Javascript for setting cookie is working incorrectly.
Script format for cookie should like this {name}={value}
Current script format is name={name}; value={value}

I made sample cookie for test in Example > ViewController > viewDidLoad()

    override func viewDidLoad() {
        super.viewDidLoad()

        let cookie = HTTPCookie(properties: [
            .domain: "github.com",
            .path: "/",
            .name: "[Test] Cookie",
            .value: "value!!"])!
        
        HTTPCookieStorage.shared.setCookie(cookie)

        setupWebView()
        webView.load(URLRequest(url: URL(string: urlString)!))
    }

And print out javascriptString

    var javaScriptString: String {
        if let values = (self.properties?
            .map { "\($0.key.rawValue)=\($0.value)" }
            .joined(separator: "; ")) {
            print("[TEST] script: \(values)")
            return values
        }

Console

[TEST] script: Discard=TRUE; Value=value!!; Path=/; Created=611202725; Name=[Test] Cookie; Domain=github.com

Safari debug
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.