Search code examples
iosflutterwkwebviewwkwebviewconfigurationflutterwebviewplugin

Flutter - Block Webview Cookies in WKWebView


Our flutter app uses webview to give users access to our online retail store. This retails store uses cookies.

This hasn’t been a problem until this week. As of last week, Apple started rejecting our updates because the webview section of the app uses cookies.

We would like to configure the webview widget to block all web cookies by default.

We’re using the webview_flutter widget, which uses WKWebView for iOS under the hood.

Is there a way to automatically block all web cookies via the webview?


Solution

  • There is a way to clear the cookies:

    final CookieManager cookieManager = CookieManager();
    final bool hasCookies = await cookieManager.clearCookies();
    

    You can check the same in the unit tests file. Attaching the file reference https://github.com/flutter/plugins/blob/master/packages/webview_flutter/webview_flutter/test/webview_flutter_test.dart