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.02k stars 1.34k forks source link

InAppWebViewController.clearAllCache() doesnt works fine #2143

Open toshiossada opened 2 weeks ago

toshiossada commented 2 weeks ago

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]

github-actions[bot] commented 2 weeks ago

👋 @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 commented 1 week ago

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