flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

InAppBrowser: cookie problems with Android

Open micmar opened this issue 2 years ago • 4 comments

Hello, I am using
Flutter 3.3.2 flutter_inappwebview: ^5.4.3+7 Android 12

with InAppBrowser.

Expected behavior: Setting app cookies with InAppBrowser will allow to fill an email field for both: iOS and Android platforms.

Current behavior: It works on iOS, not on Android.

I am using this code:

var options = InAppBrowserClassOptions(
  crossPlatform: InAppBrowserOptions(
    hideToolbarTop: true,
    hideUrlBar: true,
  ),
  inAppWebViewGroupOptions: InAppWebViewGroupOptions(
    crossPlatform: InAppWebViewOptions(javaScriptEnabled: true),
  ),
  ios: IOSInAppBrowserOptions(
      presentationStyle: IOSUIModalPresentationStyle.PAGE_SHEET),
);

await webView.openUrlRequest(
  urlRequest: URLRequest(
    url: initialRoute,
  ),
  options: options,
);

And then I set cookies like this:

CookieManager cookieManager = CookieManager.instance();

await cookieManager.deleteAllCookies();

await cookieManager.setCookie(
  url: Uri.parse(_myInitialRoute()),
  name: 'email',
  value: emailAddress,
  domain: _currentDomain(),   // << NOTE this line
);

The goal is to open a web view with an email address pre filled in. About the last line: I need to use this with iOS, otherwise the email will not be set. But as it is, this code DOES WORK with iOS.

But if I move to Android I have a funny behaviour. I check cookies with following code:

// get cookies
List<Cookie> cookies =
    await cookieManager.getCookies(url: Uri.parse(_myInitialRoute()));

If I keep this line: domain: _currentDomain(),

I will NOT get any cookie on Android. If I remove it then there will be the one cookie I set.

Either case, even if the cookie is there, the email address is never pre-filled in on Android.

Any clue about what is going on? Thanks, Mik

micmar avatar Sep 19 '22 14:09 micmar

👋 @micmar

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

github-actions[bot] avatar Sep 19 '22 14:09 github-actions[bot]

Hello, any update regarding this bug?

davideravasi avatar Oct 18 '23 07:10 davideravasi

Hello, any update? I've seen in the answer https://github.com/pichillilorenzo/flutter_inappwebview/issues/1483 that there should be a way to make this work, can you confirm this?

davideravasi avatar Jan 22 '24 13:01 davideravasi

@pichillilorenzo Don't know if it was addressed in a different issue, but the behavior here looks a little strange. Are you aware of someone already handling this? Could this be related to the underlying Google's webview?

mludovico avatar Jan 22 '24 13:01 mludovico

Issue has been solved with: upgrading the library and using the full path in the URL when setCookies is called We can close this issue (all users in this thread were working on the same product 👍 )

davideravasi avatar Jan 25 '24 11:01 davideravasi

it is not working with me can someone please add more details?!!! I am using latest update on this library and got latest flutter update set the cookie for domain and the full path the issue is still remaining

aliazxs avatar Jun 04 '24 11:06 aliazxs