setCookie method
- String name,
- String value, {
- String? url,
- String? domain,
- String? path,
- bool? secure,
- bool? httpOnly,
- CookieSameSite? sameSite,
- TimeSinceEpoch? expires,
- CookiePriority? priority,
- bool? sameParty,
- CookieSourceScheme? sourceScheme,
- int? sourcePort,
- String? partitionKey,
Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
name
Cookie name.
value
Cookie value.
url
The request-URI to associate with the setting of the cookie. This value can affect the
default domain, path, source port, and source scheme values of the created cookie.
domain
Cookie domain.
path
Cookie path.
secure
True if cookie is secure.
httpOnly
True if cookie is http-only.
sameSite
Cookie SameSite type.
expires
Cookie expiration date, session cookie if not set
priority
Cookie Priority type.
sameParty
True if cookie is SameParty.
sourceScheme
Cookie source scheme type.
sourcePort
Cookie source port. Valid values are {-1, 1, 65535
}, -1 indicates an unspecified port.
An unspecified port value allows protocol clients to emulate legacy cookie scope for the port.
This is a temporary ability and it will be removed in the future.
partitionKey
Cookie partition key. The site of the top-level URL the browser was visiting at the start
of the request to the endpoint that set the cookie.
If not set, the cookie will be set as not partitioned.
Returns: Always set to true. If an error occurs, the response indicates protocol error.
Implementation
Future<bool> setCookie(String name, String value,
{String? url,
String? domain,
String? path,
bool? secure,
bool? httpOnly,
CookieSameSite? sameSite,
TimeSinceEpoch? expires,
CookiePriority? priority,
bool? sameParty,
CookieSourceScheme? sourceScheme,
int? sourcePort,
String? partitionKey}) async {
var result = await _client.send('Network.setCookie', {
'name': name,
'value': value,
if (url != null) 'url': url,
if (domain != null) 'domain': domain,
if (path != null) 'path': path,
if (secure != null) 'secure': secure,
if (httpOnly != null) 'httpOnly': httpOnly,
if (sameSite != null) 'sameSite': sameSite,
if (expires != null) 'expires': expires,
if (priority != null) 'priority': priority,
if (sameParty != null) 'sameParty': sameParty,
if (sourceScheme != null) 'sourceScheme': sourceScheme,
if (sourcePort != null) 'sourcePort': sourcePort,
if (partitionKey != null) 'partitionKey': partitionKey,
});
return result['success'] as bool;
}