Closed iverc closed 4 years ago
Hi! I would like to help but I need some input from you.
await Future.delay(Duration(seconds:3))
, and then get cookies again. Any result appears?HI @fryette, thanks for quick response.
final gotCookies = await cookieManager.getCookies('https://youtube.com');
When I do that on Android, everything works as expected and I get an array of cookies. Doing the same on iOS device returns an empty array.Thank you!
It would be nice to have a function like getAllCookies. In hasCookies, something says there is a cookie... I don't know what cookies are in flutter.
@JosephNK do you know a native way to implement it?
@fryette I checked the ios native source. When you call getCookies(null), you get all cookies. :)
Strangely, when calling getCookies(null) in ios, there are times when cookie cannot be fetched.
Please consider importing as HTTPCookieStorage.shared.cookies, not WKWebsiteDataStore.default().httpCookieStore.
@JosephNK but for android you cannot, right?
@fryette PR[#21] please check. i am currently not able to check Android. and the PR part has been modified so that it does not conflict with android.
@JosephNK will check it today or tomorrow morning and will provide a new version if everything is OK
i have same issue. I can't get cookie from ios.
Same problem for me.
@seukaiwokeo @i-Senku could you please grab PR(https://github.com/fryette/webview_cookie_manager/pull/21) and check it?
It can be done with:
webview_cookie_manager:
git:
url: https://github.com/JosephNK/webview_cookie_manager.git
If everything starts to work for both of you, I will immediately produce a new version with these changes.
@fryette It's doesn't work. getCookies functions returned empty Cookie List.
@i-Senku When you set getCookies(null), in the case of Android, an empty list is correct. The reason is that Android can't get all the lists. And in the case of iOS, a list should appear. Did you test on Android? Did you do it with iOS?
@JosephNK yep i tested on IOS with offical webview package. But it return empty list. Did you tested on IOS ? Because it's doesnt work on my project :(
@i-Senku yep i tested on iOS. It works in my project with a modified version.
After modifying as below in the pubspec.yaml file
webview_flutter: ^1.0.7
webview_cookie_manager:
git:
url: https://github.com/JosephNK/webview_cookie_manager.git
ref: 65979e2064fcdf5d98c0b2159ca5f4873f0259d8
After executing the command as below
$ flutter clean
$ flutter pub get
Try build
Run build iOS
@JosephNK
Webview Scene. I added breakpoint to getCookies function and it looks empty. Where am i doing wrong ?
return SafeArea(
child: Scaffold(
body: WebView(
initialUrl: "https://www.instagram.com/accounts/login/",
javascriptMode: JavascriptMode.unrestricted,
onPageFinished: (url) async {
var cookies = await cookieManager.getCookies(url);
cookies.forEach((element) {
print(element.name);
});
},
),
));
pubspec file.
@i-Senku
getCookies(url) to getCookies(null)
can u try?
@i-Senku
When flutter passes the url value as a parameter, if you check the iOS native code, there may be cases where the host of the url value does not match when searching for the cookie value in the cookie storage. For example, in case of a wildcard, a case of mismatch occurs.
idk why i tried this code ( getCookies(null) ). What should I do now? Do you have a solution? I want to receive cookies from Instagram
@i-Senku @fryette
Oops... I think the error is... I think you need to check the Future<List
@i-Senku @fryette
Fixed Invalid Char issue when creating a cookie for darts. https://github.com/fryette/webview_cookie_manager/pull/21/commits/70e8e0cbc7cfacfbb7abb7917e70a78a0744681b
This error is an error when creating a cookie for darts.
So, I modified the "Future getCookies(String currentUrl)" function.
ı fixed get cookies problem in ios. I founded problem in getCookies function. This code working
func getCookies(result: @escaping FlutterResult){
var cookieList = [[String: Any]]()
let cookieStore = WKWebsiteDataStore.default().httpCookieStore
cookieStore.getAllCookies { (cookies) in
for cookie in cookies {
cookieList.append(cookieToDictionary(cookie: cookie))
}
result(cookieList)
}
}
@JosephNK maybe we also can include @i-Senku changes to PR? Or your fix also fix it?
@fryette I don't know what kind of code he solved. I already PR the Invalid Char issue.
@fryette u check out the PR code. or try testing.
@JosephNK give me a few hours
@JosephNK merged and 1.0.4 version provided. Thx for your contribution! If anyone has problems with the new version, feel free to reopen an issue or create a new one
@fryette Might be a bit late, tried to raise PR with a fix right away but did not have permission for it. 🤣
In my particular case, the problem with was the part of logic that did URL check. it was too strict, so if you were on a website with a prefix (e.g. m.website.com), the .contains()
check for URL match failed and no cookies were returned. The fix was about doing a mirrored check to account for website prefixes. Hope it could be helpful
@fryette Actually It looks like the problem is still there (unless you set URL tonull
). I can't add a branch or a PR with the fix, could you please allow it?
@iverc Feel free to fork repo and then you can create a PR with fix
@iverc new version availbale (1.0.6)
It works as expected on Android, but on iOS (11.0+) it returns empty array. Flutter code is equivalent for both platforms, so I suppose there is an issue when interacting with native iOS cookie manager.