pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.31k stars 1.64k forks source link

InAppBrowser: cookie problems with Android #1326

Closed micmar closed 10 months ago

micmar commented 2 years ago

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

github-actions[bot] commented 2 years ago

šŸ‘‹ @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!

davideravasi commented 1 year ago

Hello, any update regarding this bug?

davideravasi commented 10 months ago

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?

mludovico commented 10 months ago

@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?

davideravasi commented 10 months ago

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 šŸ‘ )

aliazxs commented 5 months ago

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

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.