Cookie.ts (6309B)
1 /** 2 * @license 3 * Copyright 2024 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * Represents the cookie's 'SameSite' status: 9 * https://tools.ietf.org/html/draft-west-first-party-cookies 10 * 11 * @public 12 */ 13 export type CookieSameSite = 'Strict' | 'Lax' | 'None'; 14 15 /** 16 * Represents the cookie's 'Priority' status: 17 * https://tools.ietf.org/html/draft-west-cookie-priority-00 18 * 19 * @public 20 */ 21 export type CookiePriority = 'Low' | 'Medium' | 'High'; 22 23 /** 24 * Represents the source scheme of the origin that originally set the cookie. A value of 25 * "Unset" allows protocol clients to emulate legacy cookie scope for the scheme. 26 * This is a temporary ability and it will be removed in the future. 27 * 28 * @public 29 */ 30 export type CookieSourceScheme = 'Unset' | 'NonSecure' | 'Secure'; 31 32 /** 33 * Represents a cookie partition key in Chrome. 34 * 35 * @public 36 */ 37 export interface CookiePartitionKey { 38 /** 39 * The site of the top-level URL the browser was visiting at the start of the request 40 * to the endpoint that set the cookie. 41 * 42 * In Chrome, maps to the CDP's `topLevelSite` partition key. 43 */ 44 sourceOrigin: string; 45 /** 46 * Indicates if the cookie has any ancestors that are cross-site to 47 * the topLevelSite. 48 * 49 * Supported only in Chrome. 50 */ 51 hasCrossSiteAncestor?: boolean; 52 } 53 54 /** 55 * Represents a cookie object. 56 * 57 * @public 58 */ 59 export interface Cookie extends CookieData { 60 /** 61 * Cookie name. 62 */ 63 name: string; 64 /** 65 * Cookie value. 66 */ 67 value: string; 68 /** 69 * Cookie domain. 70 */ 71 domain: string; 72 /** 73 * Cookie path. 74 */ 75 path: string; 76 /** 77 * Cookie expiration date as the number of seconds since the UNIX epoch. Set to `-1` for 78 * session cookies 79 */ 80 expires: number; 81 /** 82 * Cookie size. 83 */ 84 size: number; 85 /** 86 * True if cookie is http-only. 87 */ 88 httpOnly: boolean; 89 /** 90 * True if cookie is secure. 91 */ 92 secure: boolean; 93 /** 94 * True in case of session cookie. 95 */ 96 session: boolean; 97 /** 98 * Cookie SameSite type. 99 */ 100 sameSite?: CookieSameSite; 101 /** 102 * Cookie Priority. Supported only in Chrome. 103 */ 104 priority?: CookiePriority; 105 /** 106 * True if cookie is SameParty. Supported only in Chrome. 107 */ 108 sameParty?: boolean; 109 /** 110 * Cookie source scheme type. Supported only in Chrome. 111 */ 112 sourceScheme?: CookieSourceScheme; 113 /** 114 * Cookie partition key. In Chrome, it is the top-level site the 115 * partitioned cookie is available in. In Firefox, it matches the 116 * source origin in the 117 * {@link https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey | PartitionKey }. 118 */ 119 partitionKey?: CookiePartitionKey | string; 120 /** 121 * True if cookie partition key is opaque. Supported only in Chrome. 122 */ 123 partitionKeyOpaque?: boolean; 124 } 125 126 /** 127 * Cookie parameter object used to set cookies in the page-level cookies 128 * API. 129 * 130 * @public 131 */ 132 export interface CookieParam { 133 /** 134 * Cookie name. 135 */ 136 name: string; 137 /** 138 * Cookie value. 139 */ 140 value: string; 141 /** 142 * The request-URI to associate with the setting of the cookie. This value can affect 143 * the default domain, path, and source scheme values of the created cookie. 144 */ 145 url?: string; 146 /** 147 * Cookie domain. 148 */ 149 domain?: string; 150 /** 151 * Cookie path. 152 */ 153 path?: string; 154 /** 155 * True if cookie is secure. 156 */ 157 secure?: boolean; 158 /** 159 * True if cookie is http-only. 160 */ 161 httpOnly?: boolean; 162 /** 163 * Cookie SameSite type. 164 */ 165 sameSite?: CookieSameSite; 166 /** 167 * Cookie expiration date, session cookie if not set 168 */ 169 expires?: number; 170 /** 171 * Cookie Priority. Supported only in Chrome. 172 */ 173 priority?: CookiePriority; 174 /** 175 * True if cookie is SameParty. Supported only in Chrome. 176 */ 177 sameParty?: boolean; 178 /** 179 * Cookie source scheme type. Supported only in Chrome. 180 */ 181 sourceScheme?: CookieSourceScheme; 182 /** 183 * Cookie partition key. In Chrome, it matches the top-level site the 184 * partitioned cookie is available in. In Firefox, it matches the 185 * source origin in the 186 * {@link https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey | PartitionKey }. 187 */ 188 partitionKey?: CookiePartitionKey | string; 189 } 190 191 /** 192 * Cookie parameter object used to set cookies in the browser-level cookies 193 * API. 194 * 195 * @public 196 */ 197 export interface CookieData { 198 /** 199 * Cookie name. 200 */ 201 name: string; 202 /** 203 * Cookie value. 204 */ 205 value: string; 206 /** 207 * Cookie domain. 208 */ 209 domain: string; 210 /** 211 * Cookie path. 212 */ 213 path?: string; 214 /** 215 * True if cookie is secure. 216 */ 217 secure?: boolean; 218 /** 219 * True if cookie is http-only. 220 */ 221 httpOnly?: boolean; 222 /** 223 * Cookie SameSite type. 224 */ 225 sameSite?: CookieSameSite; 226 /** 227 * Cookie expiration date, session cookie if not set 228 */ 229 expires?: number; 230 /** 231 * Cookie Priority. Supported only in Chrome. 232 */ 233 priority?: CookiePriority; 234 /** 235 * True if cookie is SameParty. Supported only in Chrome. 236 */ 237 sameParty?: boolean; 238 /** 239 * Cookie source scheme type. Supported only in Chrome. 240 */ 241 sourceScheme?: CookieSourceScheme; 242 /** 243 * Cookie partition key. In Chrome, it matches the top-level site the 244 * partitioned cookie is available in. In Firefox, it matches the 245 * source origin in the 246 * {@link https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey | PartitionKey }. 247 */ 248 partitionKey?: CookiePartitionKey | string; 249 } 250 251 /** 252 * @public 253 */ 254 export interface DeleteCookiesRequest { 255 /** 256 * Name of the cookies to remove. 257 */ 258 name: string; 259 /** 260 * If specified, deletes all the cookies with the given name where domain and path match 261 * provided URL. Otherwise, deletes only cookies related to the current page's domain. 262 */ 263 url?: string; 264 /** 265 * If specified, deletes only cookies with the exact domain. 266 */ 267 domain?: string; 268 /** 269 * If specified, deletes only cookies with the exact path. 270 */ 271 path?: string; 272 /** 273 * If specified, deletes cookies in the given partition key. In 274 * Chrome, partitionKey matches the top-level site the partitioned 275 * cookie is available in. 276 * In Firefox, it matches the source origin in the 277 * {@link https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey | PartitionKey }. 278 */ 279 partitionKey?: CookiePartitionKey | string; 280 }