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

InAppWebViewController.clearAllCache() doesnt works fine #2143

Closed
2 tasks done
toshiossada opened this issue May 14, 2024 · 9 comments
Closed
2 tasks done

InAppWebViewController.clearAllCache() doesnt works fine #2143

toshiossada opened this issue May 14, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@toshiossada
Copy link

  • I have read the Getting Started section
  • 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

  1. This
  2. Than that
  3. 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 toshiossada added the bug Something isn't working label May 14, 2024
Copy link

👋 @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!

@EArminjon
Copy link
Contributor

EArminjon commented May 18, 2024

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();
  }
}

@paulVulog
Copy link

Hi,
Any Update on it @toshiossada ?
Relates to #2034
Absolutely no update - this lib is kinda dying....

@toshiossada
Copy link
Author

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 :(

@EArminjon
Copy link
Contributor

(did my response helped you ?)

@toshiossada
Copy link
Author

(did my response helped you ?)

Didn't work, I just change to webview_flutter

@BriceFab
Copy link

BriceFab commented Oct 1, 2024

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.

@pichillilorenzo
Copy link
Owner

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:

public void clearAllCache() {
clearCache(true);
clearCookies();
clearFormData();
WebStorage.getInstance().deleteAllData();
}

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

Copy link

github-actions bot commented Nov 5, 2024

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 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants