Flutter Webview plugin doesn't save session cookies on iOS?
To achieve the same results as on Android on an iOS Platform you have to make sure that your WebViews are created from the same WebView pool. Unfortunately, the current version of the FlutterWebViewPlugin does not support such behavior.
You can use this Fork instead. Just be clear: Using will cause all your WebViews to created from the same pool. If that's not an issue, go ahead.
InternetJohnny
Updated on December 17, 2022Comments
-
InternetJohnny over 1 year
I am developing a simple app on Android Studio using Flutter and the flutter_webview_plugin.
The starting url is a login page. After logging in, I close the app and then reopen it. Upon re-opening, I am still logged in on Android, but on iOS I am shown the login page again.
How can I preserve the session cookies?
I have already set
clearCookies: false,
when instantiating the plugin. I have seen some mentions here about NSHTTPCookieStorage on iOS, but am not sure if this is the key to fixing my problem.Here is my code:
import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; class WebView extends StatelessWidget { final String selectedUrl = "https://servicedesk.roff.pt/suporte"; @override Widget build(BuildContext context) { return new SafeArea( left: false, top: true, right: false, bottom: false, child: WebviewScaffold( url: selectedUrl, withZoom: true, withLocalStorage: true, clearCookies: false, hidden: true, initialChild: Container( color: Colors.black, child: const Center( child: Padding( padding: EdgeInsets.all(8.0), child: Image( image: AssetImage('lib/assets/splash.png'), ), ), ), ), ), ); } }
All help is appreciated
-
InternetJohnny about 4 yearsI tried it but this did not solve the issue on iOS. If I login on my website and then close the app, when I reopen it I have to login again. This does not happen on Android (the session is preserved). Any suggestions?
-
J T about 4 yearsIn my case the solution was to use the flutter_secure_storage plugin to save the credentials. In my use-case it was better to do a new login each time I open the app(even on android) as that way you refresh your WebView's session which prevents token-invalidation.
-
InternetJohnny about 4 yearsThanks, this is exactly what I ended up going for. Built myself a login screen, the user is able to store the credentials if they want, and then I use evalJavascript from flutter_webview_plugin to automatically log them in. The flutter_secure_storage plugin is gonna work like a charm
-
Cyrus the Great over 3 yearsWhat is
WebView pool
and how can i set cookies with this fork: pub.dev/packages/flutter_webview_plugin @JTLtManBearPig