kofktu / wkcookiewebview Goto Github PK
View Code? Open in Web Editor NEWWKWebView with cookie sharing support
License: MIT License
WKWebView with cookie sharing support
License: MIT License
Migration to Swift 4.2
XCode 10.x
I have encountered that when the security attribute of the cookie is true, the cookie will be lost after I reopen the app. I would be very grateful if I could solve my problem.
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:
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.
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?
When I visit www.overstock.com, log in and then sign out, the status is still log in if I re-enter the app. I checked the cookies and found out the cookies could not be deleted on signing out.
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도 저장되어 출력이 안되는 것 같아서 문의 남겨요!
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.