Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CookieManager.instance.flush() #2354

Closed
2 tasks done
EArminjon opened this issue Oct 17, 2024 · 9 comments
Closed
2 tasks done

CookieManager.instance.flush() #2354

EArminjon opened this issue Oct 17, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@EArminjon
Copy link
Contributor

EArminjon commented Oct 17, 2024

Is there an existing feature request for this?

  • I have searched the existing feature request

Operating System

Android

Pain

I've the same issue as react-native-webview/react-native-webview#1345.

If you remove a cookie in the web view and then kill the application in the recent application list on Android. When you launch again the application, the cookie is still here.
He does the same if you set a cookie and kill the app few seconds after, the cookie will not be here.
It seems ok on iOS.

Suggested solution

Adding a method to manually call Android getCookieManager().flush();

https://github.com/react-native-cookies/cookies/blob/69fe6557b0f2c286e6df6fa9100391ad2d163860/android/src/main/java/com/reactnativecommunity/cookies/CookieManagerModule.java#L96

A temporary solution is to delete a random fake cookie :

await CookieManager.instance().deleteCookie(url: WebUri('https://example.com'), name: 'i_need_to_call_flush');

This will call on Android getCookieManager().flush(); without regarding if deletion succeed or failed.

Useful resources

https://developer.android.com/reference/android/webkit/CookieManager#flush()

Additional information

Flutter 3.24

Self grab

  • I'm ready to work on this issue!
@EArminjon EArminjon added the enhancement New feature or request label Oct 17, 2024
@pichillilorenzo
Copy link
Owner

flush is already called when setting or deleting cookies on Android, for example:

Maybe the flush() method call should be moved inside the public void onReceiveValue(Boolean successful) { callback instead after the setCookie method call ??

@EArminjon
Copy link
Contributor Author

EArminjon commented Oct 17, 2024

Sorry, i was not enough precise.

The issue is present when a cookie is set or removed by a webpage (not by Flutter). In this case, if user kill the app few times after and relaunch it, cookie will not be here (in case of creation) or still be here (in case of deletion).

For example we have a scenario where when an users launch the app, they can see a webview to accept or not cookie "consent" (for tracking purpose). Once accepted or rejected we receive a postMessage from our webview to inform us to close the webview.
We detected this issue in this case : later, if user kill the app and relaunch it, consent is not persisted.

That's why we found calling .flush() before closing webview seems to well fix the issue.

@pichillilorenzo
Copy link
Owner

Ok, clear now, thanks! So then I will expose that method on Android as soon as possible 👍

@EArminjon
Copy link
Contributor Author

You rock ! Ty so much !

@EArminjon
Copy link
Contributor Author

Exposing flush() will be great and can help other future scenario on Android.

We got also the issue on iOS but this time we didn't have any suggestion / solution. I can create a dedicated issue if you want.

@pichillilorenzo
Copy link
Owner

iOS doesn't have any "flush()" method: https://developer.apple.com/documentation/webkit/wkhttpcookiestore

@EArminjon
Copy link
Contributor Author

EArminjon commented Oct 17, 2024

Yes, will create new issue for iOS, it will be clean.

@pichillilorenzo
Copy link
Owner

Released new version 6.2.0-beta.1.

hson252850 pushed a commit to hson252850/flutter_inappwebview that referenced this issue Nov 7, 2024
…tic method, Added CookieManager.flush method, Updated InAppWebViewController.takeScreenshot implementation to support screenshot out of visible viewport when InAppWebViewController.enableSlowWholeDocumentDraw is called, fix pichillilorenzo#2354
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants