deleteCookies method

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'CookieManager.getCookie', apiUrl: 'https://developer.android.com/reference/android/webkit/CookieManager#getCookie(java.lang.String)'), IOSPlatform(apiName: 'WKHTTPCookieStore.delete', apiUrl: 'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete', note: """On iOS below 11.0, the [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript (cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work. In this case the [url] parameter is ignored. If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView] to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!). In this case, this method will return always `true`."""), MacOSPlatform(apiName: 'WKHTTPCookieStore.delete', apiUrl: 'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete', note: """On macOS below 10.13, the [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript (cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work. In this case the [url] parameter is ignored. If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView] to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!). In this case, this method will return always `true`."""), WebPlatform(note: """The [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript (cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work. In this case the [url] parameter is ignored. If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView] to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!). In this case, this method will return always `true`."""), WindowsPlatform(note: 'The [webViewController] could be used to access cookies accessible only on the WebView managed by that controller, such as cookie with partition key.'), LinuxPlatform(apiName: 'webkit_cookie_manager_delete_cookie', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.CookieManager.delete_cookie.html')])
Future<bool> deleteCookies({
  1. required WebUri url,
  2. String path = "/",
  3. String? domain,
  4. @Deprecated("Use webViewController instead") PlatformInAppWebViewController? iosBelow11WebViewController,
  5. @SupportedPlatforms.new(platforms: [MacOSPlatform(), IOSPlatform(), WebPlatform(), WindowsPlatform()]) PlatformInAppWebViewController? webViewController,
})

Removes all cookies for the given url, domain and path.

The default value of path is "/".

The return value indicates whether cookies were deleted successfully.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • url: all platforms
  • path: all platforms
  • domain: all platforms
  • webViewController:
    • macOS WKWebView
    • iOS WKWebView
    • Web <iframe> but requires same origin
    • Windows WebView2

Use the PlatformCookieManager.isMethodSupported method to check if this method is supported at runtime.

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'CookieManager.getCookie',
      apiUrl:
          'https://developer.android.com/reference/android/webkit/CookieManager#getCookie(java.lang.String)',
    ),
    IOSPlatform(
      apiName: 'WKHTTPCookieStore.delete',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete',
      note:
          """On iOS below 11.0, the [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript
(cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)
from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work.
In this case the [url] parameter is ignored.
If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!).
In this case, this method will return always `true`.""",
    ),
    MacOSPlatform(
      apiName: 'WKHTTPCookieStore.delete',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete',
      note:
          """On macOS below 10.13, the [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript
(cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)
from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work.
In this case the [url] parameter is ignored.
If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!).
In this case, this method will return always `true`.""",
    ),
    WebPlatform(
      note:
          """The [webViewController] is used for deleting the cookies (also session-only cookies) using JavaScript
(cookies with `isHttpOnly` enabled cannot be deleted, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)
from the current context of the `WebView` managed by that controller. JavaScript must be enabled in order to work.
In this case the [url] parameter is ignored.
If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!).
In this case, this method will return always `true`.""",
    ),
    WindowsPlatform(
      note:
          'The [webViewController] could be used to access cookies accessible only on the WebView managed by that controller, such as cookie with partition key.',
    ),
    LinuxPlatform(
      apiName: 'webkit_cookie_manager_delete_cookie',
      apiUrl:
          'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.CookieManager.delete_cookie.html',
    ),
  ],
)
Future<bool> deleteCookies({
  required WebUri url,
  String path = "/",
  String? domain,
  @Deprecated("Use webViewController instead")
  PlatformInAppWebViewController? iosBelow11WebViewController,
  @SupportedPlatforms(
    platforms: [
      MacOSPlatform(),
      IOSPlatform(),
      WebPlatform(),
      WindowsPlatform(),
    ],
  )
  PlatformInAppWebViewController? webViewController,
}) {
  throw UnimplementedError(
    'deleteCookies is not implemented on the current platform',
  );
}