getCookie method
- @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')])
- required WebUri url,
- required String name,
- @Deprecated("Use webViewController instead") PlatformInAppWebViewController? iosBelow11WebViewController,
- @SupportedPlatforms.new(platforms: [MacOSPlatform(), IOSPlatform(), WebPlatform(), WindowsPlatform()]) PlatformInAppWebViewController? webViewController,
Gets a cookie by its name for the given url.
Officially Supported Platforms/Implementations:
- Android WebView (Official API - CookieManager.getCookie)
- iOS WKWebView (Official API - WKHTTPCookieStore.getAllCookies):
- On iOS below 11.0, the
webViewControlleris used for getting the cookie (also session-only cookie) using JavaScript (cookie withisHttpOnlyenabled cannot be found, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of theWebViewmanaged by that controller. JavaScript must be enabled in order to work. In this case theurlparameter is ignored. All the cookies returned this way will have all the properties tonullexcept for Cookie.name and Cookie.value. IfwebViewControllerisnullor JavaScript is disabled for it, it will try to use a PlatformHeadlessInAppWebView to get the cookie (session-only cookie and cookie withisHttpOnlyenabled won't be found!).
- On iOS below 11.0, the
- macOS WKWebView (Official API - WKHTTPCookieStore.getAllCookies):
- On macOS below 10.13, the
webViewControlleris used for getting the cookie (also session-only cookie) using JavaScript (cookie withisHttpOnlyenabled cannot be found, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of theWebViewmanaged by that controller. JavaScript must be enabled in order to work. In this case theurlparameter is ignored. All the cookies returned this way will have all the properties tonullexcept for Cookie.name and Cookie.value. IfwebViewControllerisnullor JavaScript is disabled for it, it will try to use a PlatformHeadlessInAppWebView to get the cookie (session-only cookie and cookie withisHttpOnlyenabled won't be found!).
- On macOS below 10.13, the
- Web <iframe> but requires same origin:
- The
webViewControlleris used for getting the cookie (also session-only cookie) using JavaScript (cookie withisHttpOnlyenabled cannot be found, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) from the current context of theWebViewmanaged by that controller. JavaScript must be enabled in order to work. In this case theurlparameter is ignored. IfwebViewControllerisnullor JavaScript is disabled for it, it will try to use a PlatformHeadlessInAppWebView to get the cookie (session-only cookie and cookie withisHttpOnlyenabled won't be found!).
- The
- Windows WebView2:
- The
webViewControllercould be used to access cookies accessible only on the WebView managed by that controller, such as cookie with partition key.
- The
- Linux WPE WebKit (Official API - webkit_cookie_manager_get_cookies)
Parameters - Officially Supported Platforms/Implementations:
url: all platformsname: all platformswebViewController:- 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',
);
}