* Sets a cookie using the provided cookie object and partition. * * @param {PartialCookie} cookie - The cookie object to set. * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to use for the cookie. * @returns {PartitionKey} The par
(cookie, partition = undefined)
| 114 | * @throws {Error} If the cookie parameter is not an instance of PartialCookie or if the partition parameter is not an instance of PartitionDescriptor. |
| 115 | */ |
| 116 | async setCookie(cookie, partition = undefined) { |
| 117 | if (!(cookie instanceof PartialCookie)) { |
| 118 | throw new Error(`Params must be an instance of PartialCookie. Received:'${cookie}'`) |
| 119 | } |
| 120 | |
| 121 | if ( |
| 122 | partition !== undefined && |
| 123 | !(partition instanceof BrowsingContextPartitionDescriptor || partition instanceof StorageKeyPartitionDescriptor) |
| 124 | ) { |
| 125 | throw new Error( |
| 126 | `Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}'`, |
| 127 | ) |
| 128 | } |
| 129 | |
| 130 | const command = { |
| 131 | method: 'storage.setCookie', |
| 132 | params: { |
| 133 | cookie: cookie ? Object.fromEntries(cookie.asMap()) : undefined, |
| 134 | partition: partition ? Object.fromEntries(partition.asMap()) : undefined, |
| 135 | }, |
| 136 | } |
| 137 | |
| 138 | let response = await this.bidi.send(command) |
| 139 | |
| 140 | if (Object.prototype.hasOwnProperty.call(response.result, 'partitionKey')) { |
| 141 | if ( |
| 142 | Object.prototype.hasOwnProperty.call(response.result.partitionKey, 'userContext') && |
| 143 | Object.prototype.hasOwnProperty.call(response.result.partitionKey, 'sourceOrigin') |
| 144 | ) { |
| 145 | return new PartitionKey(response.result.partitionKey.userContext, response.result.partitionKey.sourceOrigin) |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Deletes cookies based on the provided filter and partition. |
no test coverage detected