← Back to Network domain

Network.setCookie

Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.

Domain: Network stable

Parameters

NameTypeDescription
namestringCookie name.
valuestringCookie value.
url (optional)stringThe 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 (optional)stringCookie domain.
path (optional)stringCookie path.
secure (optional)booleanTrue if cookie is secure.
httpOnly (optional)booleanTrue if cookie is http-only.
sameSite (optional)CookieSameSiteCookie SameSite type.
expires (optional)TimeSinceEpochCookie expiration date, session cookie if not set
priority (optional)CookiePriorityCookie Priority type.
sourceScheme (optional)CookieSourceSchemeCookie source scheme type.
sourcePort (optional)integerCookie 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 (optional)CookiePartitionKeyCookie partition key. If not set, the cookie will be set as not partitioned.

Returns

NameTypeDescription
successbooleanAlways set to true. If an error occurs, the response indicates protocol error.

Example Request

{
  "id": 1,
  "method": "Network.setCookie",
  "params": {
    "name": "example-name",
    "value": "example-value"
  }
}

Example Response

{
  "id": 1,
  "result": {
    "success": true
  }
}

Usage in Node.js

const result = await send('Network.setCookie', {"name": "example-name", "value": "example-value"});
console.log(result);
// {"success": true}