MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Storage

Class Storage

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

* Represents commands of Storage module. * Described in https://w3c.github.io/webdriver-bidi/#module-storage. * @class

Source from the content-addressed store, hash-verified

27 * @class
28 */
29class Storage {
30 constructor(driver) {
31 this._driver = driver
32 }
33
34 async init() {
35 if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
36 throw Error('WebDriver instance must support BiDi protocol')
37 }
38
39 this.bidi = await this._driver.getBidi()
40 }
41
42 /**
43 * Retrieves cookies based on the provided filter and partition.
44 *
45 * @param {CookieFilter} [filter] - The filter to apply to the cookies.
46 * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to retrieve cookies from.
47 * @returns {Promise<{ cookies: Cookie[], partitionKey: (PartitionKey|undefined) }>} - A promise that resolves to an object containing the retrieved cookies and an optional partition key.
48 * @throws {Error} If the filter parameter is provided but is not an instance of CookieFilter.
49 * @throws {Error} If the partition parameter is provided but is not an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor.
50 */
51 async getCookies(filter = undefined, partition = undefined) {
52 if (filter !== undefined && !(filter instanceof CookieFilter)) {
53 throw new Error(`Params must be an instance of CookieFilter. Received:'${filter}'`)
54 }
55
56 if (
57 partition !== undefined &&
58 !(partition instanceof BrowsingContextPartitionDescriptor || partition instanceof StorageKeyPartitionDescriptor)
59 ) {
60 throw new Error(
61 `Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}'`,
62 )
63 }
64
65 const command = {
66 method: 'storage.getCookies',
67 params: {
68 filter: filter ? Object.fromEntries(filter.asMap()) : undefined,
69 partition: partition ? Object.fromEntries(partition.asMap()) : undefined,
70 },
71 }
72
73 let response = await this.bidi.send(command)
74
75 let cookies = []
76 response.result.cookies.forEach((cookie) => {
77 cookies.push(
78 new Cookie(
79 cookie.name,
80 new BytesValue(cookie.value.type, cookie.value.value),
81 cookie.domain,
82 cookie.path,
83 cookie.size,
84 cookie.httpOnly,
85 cookie.secure,
86 cookie.sameSite,

Callers 2

storageMethod · 0.90
storage_test.jsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected