MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / setCookie

Method setCookie

javascript/selenium-webdriver/bidi/storage.js:116–148  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 2

storage_test.jsFile · 0.45
storage_test.jsFile · 0.45

Calls 3

asMapMethod · 0.65
sendMethod · 0.65
callMethod · 0.65

Tested by

no test coverage detected