flutter_inappwebview
flutter_inappwebview copied to clipboard
InAppWebViewController.clearAllCache() doesnt works fine
- [x] I have read the Getting Started section
- [x] I have already searched for the same problem
Environment
| Technology | Version |
|---|---|
| Flutter version | 3.19.6 |
| Plugin version | 6.0.0 |
| Android version | 14 |
| iOS version | |
| macOS version | |
| Xcode version | |
| Google Chrome version |
Device information: Google Pixel 8 PRO
Description
I have a login page thats I capture toekn by webview, currently I'm using controller.clearCache(); and works great, but this was deprecated and ask to use InAppWebViewController.clearAllCache instead, but when I changed to use the new way the cache dont be cleared anymore
Expected behavior:
Current behavior:
Steps to reproduce
- This
- Than that
- Then
Stacktrace/Logcat
D/InAppWebView(32290): Using InAppWebViewClientCompat implementation [AndroidInAppWebViewWidget] (android) AndroidInAppWebViewWidget ID 3 calling "onWebViewCreated" using [] W/cr_WebSettings(32290): setForceDark() is a no-op in an app with targetSdkVersion>=T W/cr_SupportWebSettings(32290): setForceDarkBehavior() is a no-op in an app with targetSdkVersion>=T I/PlatformViewsController(32290): Using hybrid composition for platform view: 3 W/WindowOnBackDispatcher(32290): OnBackInvokedCallback is not enabled for the application. W/WindowOnBackDispatcher(32290): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest. [AndroidInAppWebViewController] (android) WebView ID 3 calling "onProgressChanged" using {progress: 10} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onReceivedHttpError" using {request: {headers: {User-Agent: Mozilla/5.0 (Linux; Android 14; Pixel 8 Pro Build/AP1A.240405.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0.6367.123 Mobile Safari/537.36, sec-ch-ua: "Chromium";v="124", "Android WebView";v="124", "Not-A.Brand";v="99", sec-ch-ua-mobile: ?1, Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7, Upgrade-Insecure-Requests: 1, sec-ch-ua-platform: "Android"}, isRedirect: false, method: GET, hasGesture: false, isForMainFrame: true, url: url_login, errorResponse: {headers: {date: Tue, 1... [AndroidInAppWebViewController] (android) WebView ID 3 calling "onLoadStart" using {url: url_login} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onProgressChanged" using {progress: 24} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onTitleChanged" using {title: FarmáciasApp} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onUpdateVisitedHistory" using {isReload: false, url: url_login} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onProgressChanged" using {progress: 70} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onReceivedTouchIconUrl" using {precomposed: false, url: url_login} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onUpdateVisitedHistory" using {isReload: false, url: url_login} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onProgressChanged" using {progress: 100} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onLoadStop" using {url: url_login} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onProgressChanged" using {progress: 100} [AndroidInAppWebViewController] (android) WebView ID 3 calling "onLoadStop" using {url: url_login} [AndroidInAppWebViewWidget] (android) AndroidInAppWebViewWidget calling "dispose" using [] W/WindowOnBackDispatcher(32290): OnBackInvokedCallback is not enabled for the application. W/WindowOnBackDispatcher(32290): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest. I/chromium(32290): [INFO:CONSOLE(1)] "[next-auth][error][CLIENT_FETCH_ERROR]
👋 @toshiossada
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!
I use this code when my user logout. I keep some cookies and delete the others.
On Android session cookies are maybe your issue.
/// Delete all cookies except the ones that are required for the webview to works
/// Then clear cache.
Future<void> clearSessionCookies() async {
final CookieManager cookieManager = CookieManager.instance();
final List<Cookie> cookies = await cookieManager.getCookies(
url: WebUri(config.webviewUrl),
);
for (final Cookie cookie in cookies) {
if (!<String>[
WEB_VIEW_COOKIE_CONSENTS,
WEB_VIEW_COOKIE_REGION_SUFFIX,
].contains(cookie.name)) {
await cookieManager.deleteCookie(
url: WebUri(config.webviewUrl),
domain: cookie.domain,
name: cookie.name,
path: cookie.path ?? WEB_VIEW_COOKIES_DEFAULT_PATH,
);
}
}
if (Platform.isAndroid) await cookieManager.removeSessionCookies();
await InAppWebViewController.clearAllCache();
}
}
Hi, Any Update on it @toshiossada ? Relates to https://github.com/pichillilorenzo/flutter_inappwebview/issues/2034 Absolutely no update - this lib is kinda dying....
Hi, Any Update on it @toshiossada ? Relates to #2034 Absolutely no update - this lib is kinda dying....
no :( they didnt give a shit to me :(
(did my response helped you ?)
(did my response helped you ?)
Didn't work, I just change to webview_flutter
Same for me ! First time it's clear cache, but second time CTA clear cache doesn't work and cache is not refreshed.
CookieManager cookieManager = CookieManager.instance();
await cookieManager.removeSessionCookies();
await cookieManager.deleteAllCookies();
await InAppWebViewController.clearAllCache();
with same webview URL called.
version 5 and version 6 have different implementations. The old one was removing more data then it should be.
On native side, the old implementation was: https://github.com/pichillilorenzo/flutter_inappwebview/blob/9447770bdfb6521dfd976fa29bc1207c9ed46c24/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java#L576-L581
and now it's only clearCache, because, as the method name says, it should clear just the cache and not other things.
For cookies and web storage data, use the corresponding service: Cookie Manager and Web Storage Manager
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.