Closed rodruiz closed 4 years ago
ping @amag2511
@rodruiz which platform?
@fryette Android.
@rodruiz Seems your WebView plugin does not use the cookie manager to set cookies. This plugin using native CookieManager to add cookies and don't have anything special in the flutter. For your case seems you need to merge both results
@fryette I'm using exactly the same plugin and code in your example file. I assume your plugin works properly with WebView.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: WebView(
initialUrl: _url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) async {
await cookieManager.setCookies([
Cookie(cookieName, cookieValue)
..domain = domain
..expires = DateTime.now().add(Duration(days: 10))
]);
},
onPageFinished: (_) async {
final gotCookies = await cookieManager.getCookies(_url);
for (var item in gotCookies) {
print(item);
}
///// CHECK WEBVIEW IS USING COOKIE MANAGER
final String cookies = await _webViewController.evaluateJavascript('document.cookie');
print('----- JS-COOKIES: $cookies -----');
},
),
),
);
@rodruiz Ok, You set cookie via cookie manager
and cannot retrieve it by
await _webViewController.evaluateJavascript('document.cookie');
?
@fryette Correct. I can retrieve all cookies available in the web document using
dart await _webViewController.evaluateJavascript('document.cookie');
, but those cookies set by the cookie manager are not present. Seems like the webview is not using the cookie manager properly.
@rodruiz We had an issue on Android as well. We cannot set cookies to Webview and decided to wrote this library. Webview definitely using cookies from Android Cookie Manager but why we cannot retrieve it via JS I don't know
@fryette If you can not get those cookies via JS means that the cookies are not included in the request to the website.
@fryette could you reopen this ticket and investigate further? Another thing this plugin does not support using a domain like this (including a dot) when setting the cookie: .mydomain.com
Hi @fryette, just want to let you know that it's working now. Setting httpOnly = false did the trick. Maybe you can add that to the README.
await cookieManager.setCookies([
Cookie(cookieName, cookieValue)
..domain = domain
..expires = DateTime.now().add(Duration(days: 10)),
..httpOnly = false, // NOW document.cookie will work
]);
Thanks!!!
WOW! Great! I will update readme!
Hi, if you check document.cookie does not match the cookie provided.
Thanks.