getCookie 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.getAllCookies', apiUrl: 'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies', note: """On iOS below 11.0, the [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript (cookie with `isHttpOnly` enabled cannot be found, 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. All the cookies returned this way will have all the properties to `null` except for [Cookie.name] and [Cookie.value]. If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView] to get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!)."""), MacOSPlatform(apiName: 'WKHTTPCookieStore.getAllCookies', apiUrl: 'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies', note: """On macOS below 10.13, the [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript (cookie with `isHttpOnly` enabled cannot be found, 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. All the cookies returned this way will have all the properties to `null` except for [Cookie.name] and [Cookie.value]. If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView] to get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!)."""), WebPlatform(note: """The [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript (cookie with `isHttpOnly` enabled cannot be found, 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 get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!)."""), 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_get_cookies', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.CookieManager.get_cookies.html')])
Future<Cookie?> getCookie({
  1. required WebUri url,
  2. required String name,
  3. @Deprecated("Use webViewController instead") PlatformInAppWebViewController? iosBelow11WebViewController,
  4. @SupportedPlatforms.new(platforms: [MacOSPlatform(), IOSPlatform(), WebPlatform(), WindowsPlatform()]) PlatformInAppWebViewController? webViewController,
})

Gets a cookie by its name for the given url.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • url: all platforms
  • name: 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.getAllCookies',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies',
      note:
          """On iOS below 11.0, the [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript
(cookie with `isHttpOnly` enabled cannot be found, 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.
All the cookies returned this way will have all the properties to `null` except for [Cookie.name] and [Cookie.value].
If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
to get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!).""",
    ),
    MacOSPlatform(
      apiName: 'WKHTTPCookieStore.getAllCookies',
      apiUrl:
          'https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies',
      note:
          """On macOS below 10.13, the [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript
(cookie with `isHttpOnly` enabled cannot be found, 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.
All the cookies returned this way will have all the properties to `null` except for [Cookie.name] and [Cookie.value].
If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
to get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!).""",
    ),
    WebPlatform(
      note:
          """The [webViewController] is used for getting the cookie (also session-only cookie) using JavaScript
(cookie with `isHttpOnly` enabled cannot be found, 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 get the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be found!).""",
    ),
    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_get_cookies',
      apiUrl:
          'https://wpewebkit.org/reference/stable/wpe-webkit-2.0/method.CookieManager.get_cookies.html',
    ),
  ],
)
Future<Cookie?> getCookie({
  required WebUri url,
  required String name,
  @Deprecated("Use webViewController instead")
  PlatformInAppWebViewController? iosBelow11WebViewController,
  @SupportedPlatforms(
    platforms: [
      MacOSPlatform(),
      IOSPlatform(),
      WebPlatform(),
      WindowsPlatform(),
    ],
  )
  PlatformInAppWebViewController? webViewController,
}) {
  throw UnimplementedError(
    'getCookie is not implemented on the current platform',
  );
}