selenium-webdriver 4.19.0 → 4.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGES.md +15 -0
  2. package/bidi/addInterceptParameters.js +28 -2
  3. package/bidi/browser.js +17 -0
  4. package/bidi/browsingContext.js +207 -25
  5. package/bidi/browsingContextInspector.js +51 -0
  6. package/bidi/browsingContextTypes.js +31 -0
  7. package/bidi/captureScreenshotParameters.js +96 -0
  8. package/bidi/clipRectangle.js +127 -0
  9. package/bidi/continueRequestParameters.js +39 -0
  10. package/bidi/continueResponseParameters.js +40 -0
  11. package/bidi/cookieFilter.js +60 -0
  12. package/bidi/createContextParameters.js +73 -0
  13. package/bidi/evaluateResult.js +17 -0
  14. package/bidi/index.js +0 -1
  15. package/bidi/input.js +27 -3
  16. package/bidi/interceptPhase.js +4 -0
  17. package/bidi/logEntries.js +66 -0
  18. package/bidi/network.js +102 -0
  19. package/bidi/networkTypes.js +346 -1
  20. package/bidi/partialCookie.js +48 -0
  21. package/bidi/partitionDescriptor.js +33 -0
  22. package/bidi/partitionKey.js +17 -0
  23. package/bidi/protocolType.js +20 -0
  24. package/bidi/protocolValue.js +129 -2
  25. package/bidi/provideResponseParameters.js +40 -0
  26. package/bidi/realmInfo.js +27 -0
  27. package/bidi/resultOwnership.js +4 -0
  28. package/bidi/scriptManager.js +119 -1
  29. package/bidi/scriptTypes.js +36 -0
  30. package/bidi/storage.js +30 -0
  31. package/bidi/urlPattern.js +35 -0
  32. package/bin/linux/selenium-manager +0 -0
  33. package/bin/macos/selenium-manager +0 -0
  34. package/bin/windows/selenium-manager.exe +0 -0
  35. package/chromium.js +12 -9
  36. package/common/driverFinder.js +36 -4
  37. package/common/seleniumManager.js +7 -39
  38. package/eslint.config.js +107 -0
  39. package/firefox.js +20 -6
  40. package/http/index.js +6 -6
  41. package/ie.js +8 -4
  42. package/index.js +11 -0
  43. package/io/exec.js +1 -1
  44. package/io/index.js +3 -2
  45. package/io/zip.js +1 -1
  46. package/lib/atoms/find-elements.js +2 -2
  47. package/lib/http.js +5 -4
  48. package/lib/input.js +0 -1
  49. package/lib/pinnedScript.js +1 -1
  50. package/lib/select.js +5 -5
  51. package/lib/until.js +3 -3
  52. package/lib/util.js +1 -0
  53. package/lib/webdriver.js +2 -2
  54. package/net/index.js +1 -1
  55. package/net/portprober.js +1 -1
  56. package/package.json +12 -6
  57. package/remote/index.js +1 -1
  58. package/remote/util.js +2 -2
  59. package/safari.js +3 -3
  60. package/testing/index.js +12 -8
@@ -0,0 +1,96 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ const { BoxClipRectangle, ElementClipRectangle } = require('./clipRectangle')
19
+
20
+ /**
21
+ * Defines the reference point from which to compute offsets for capturing screenshot.
22
+ *
23
+ * @enum {string}
24
+ */
25
+ const Origin = {
26
+ VIEWPORT: 'viewport',
27
+ DOCUMENT: 'document',
28
+ }
29
+
30
+ /**
31
+ * Represents the optional parameters for capturing a screenshot.
32
+ * Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.
33
+ */
34
+ class CaptureScreenshotParameters {
35
+ #map = new Map()
36
+
37
+ /**
38
+ * Sets the origin for capturing the screenshot.
39
+ *
40
+ * @param {Origin} origin - The origin for capturing the screenshot. Must be one of `Origin.VIEWPORT` or `Origin.DOCUMENT`.
41
+ * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.
42
+ * @throws {Error} - If the provided origin is not valid.
43
+ */
44
+ origin(origin) {
45
+ if (origin !== Origin.VIEWPORT && origin !== Origin.DOCUMENT) {
46
+ throw new Error(`Origin must be one of ${Object.values(Origin)}. Received:'${origin}'`)
47
+ }
48
+ this.#map.set('origin', origin)
49
+ return this
50
+ }
51
+
52
+ /**
53
+ * Sets the image format and quality for capturing a screenshot.
54
+ *
55
+ * @param {string} type - The image format type.
56
+ * @param {number} [quality] - The image quality (optional).
57
+ * @throws {Error} If the type is not a string or if the quality is not a number.
58
+ * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.
59
+ */
60
+ imageFormat(type, quality = undefined) {
61
+ if (typeof type !== 'string') {
62
+ throw new Error(`Type must be an instance of String. Received:'${type}'`)
63
+ }
64
+
65
+ this.#map.set('type', type)
66
+
67
+ if (quality !== undefined) {
68
+ if (typeof quality !== 'number') {
69
+ throw new Error(`Quality must be a number. Received:'${quality}'`)
70
+ }
71
+ this.#map.set('quality', quality)
72
+ }
73
+ return this
74
+ }
75
+
76
+ /**
77
+ * Sets the clip rectangle for capturing a screenshot.
78
+ *
79
+ * @param {BoxClipRectangle|ElementClipRectangle} clipRectangle - The clip rectangle to set.
80
+ * @throws {Error} If the clipRectangle is not an instance of ClipRectangle.
81
+ * @returns {CaptureScreenshotParameters} - The current instance of the CaptureScreenshotParameters for chaining.
82
+ */
83
+ clipRectangle(clipRectangle) {
84
+ if (!(clipRectangle instanceof BoxClipRectangle || clipRectangle instanceof ElementClipRectangle)) {
85
+ throw new Error(`ClipRectangle must be an instance of ClipRectangle. Received:'${clipRectangle}'`)
86
+ }
87
+ this.#map.set('clip', Object.fromEntries(clipRectangle.asMap()))
88
+ return this
89
+ }
90
+
91
+ asMap() {
92
+ return this.#map
93
+ }
94
+ }
95
+
96
+ module.exports = { CaptureScreenshotParameters, Origin }
@@ -0,0 +1,127 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ /**
19
+ * Represents a clip rectangle.
20
+ * Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-captureScreenshot.
21
+ */
22
+ class ClipRectangle {
23
+ clipType
24
+
25
+ /**
26
+ * Constructs a new ClipRectangle object.
27
+ * @param {string} type - The type of the clip rectangle.
28
+ */
29
+ constructor(type) {
30
+ this.clipType = type
31
+ }
32
+
33
+ /**
34
+ * Gets the type of the clip rectangle.
35
+ * @returns {string} The type of the clip rectangle.
36
+ */
37
+ get type() {
38
+ return this.clipType
39
+ }
40
+
41
+ asMap() {}
42
+ }
43
+
44
+ /**
45
+ * Represents a clip rectangle for an element.
46
+ * @extends ClipRectangle
47
+ */
48
+ class ElementClipRectangle extends ClipRectangle {
49
+ #sharedId
50
+ #handleId
51
+
52
+ /**
53
+ * Constructs a new ElementClipRectangle instance.
54
+ * @param {string} sharedId - The shared ID of the element.
55
+ * @param {string} [handleId] - The handle ID of the element (optional).
56
+ */
57
+ constructor(sharedId, handleId = undefined) {
58
+ super('element')
59
+ this.#sharedId = sharedId
60
+
61
+ if (handleId !== undefined) {
62
+ this.#handleId = handleId
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Converts the ElementClipRectangle instance to a map.
68
+ * @returns {Map} - The converted map.
69
+ */
70
+ asMap() {
71
+ const map = new Map()
72
+ map.set('type', super.type)
73
+
74
+ const sharedReference = new Map()
75
+ sharedReference.set('sharedId', this.#sharedId)
76
+ if (this.#handleId !== undefined) {
77
+ sharedReference.set('handleId', this.#handleId)
78
+ }
79
+
80
+ map.set('element', Object.fromEntries(sharedReference))
81
+
82
+ return map
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Represents a box-shaped clip rectangle.
88
+ * @extends ClipRectangle
89
+ */
90
+ class BoxClipRectangle extends ClipRectangle {
91
+ #x
92
+ #y
93
+ #width
94
+ #height
95
+
96
+ /**
97
+ * Constructs a new BoxClipRectangle object.
98
+ * @param {number} x - The x-coordinate of the top-left corner of the rectangle.
99
+ * @param {number} y - The y-coordinate of the top-left corner of the rectangle.
100
+ * @param {number} width - The width of the rectangle.
101
+ * @param {number} height - The height of the rectangle.
102
+ */
103
+ constructor(x, y, width, height) {
104
+ super('box')
105
+ this.#x = x
106
+ this.#y = y
107
+ this.#width = width
108
+ this.#height = height
109
+ }
110
+
111
+ /**
112
+ * Converts the BoxClipRectangle object to a Map.
113
+ * @returns {Map<string, any>} - The Map representation of the BoxClipRectangle object.
114
+ */
115
+ asMap() {
116
+ const map = new Map()
117
+ map.set('type', super.type)
118
+ map.set('x', this.#x)
119
+ map.set('y', this.#y)
120
+ map.set('width', this.#width)
121
+ map.set('height', this.#height)
122
+
123
+ return map
124
+ }
125
+ }
126
+
127
+ module.exports = { BoxClipRectangle, ElementClipRectangle }
@@ -17,6 +17,10 @@
17
17
 
18
18
  const { BytesValue, Header } = require('./networkTypes')
19
19
 
20
+ /**
21
+ * Represents the parameters for a continue request command.
22
+ * Described in https://w3c.github.io/webdriver-bidi/#command-network-continueRequest.
23
+ */
20
24
  class ContinueRequestParameters {
21
25
  #map = new Map()
22
26
 
@@ -24,6 +28,13 @@ class ContinueRequestParameters {
24
28
  this.#map.set('request', request)
25
29
  }
26
30
 
31
+ /**
32
+ * Sets the body value for the request.
33
+ *
34
+ * @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.
35
+ * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
36
+ * @throws {Error} - If the value is not an instance of BytesValue.
37
+ */
27
38
  body(value) {
28
39
  if (!(value instanceof BytesValue)) {
29
40
  throw new Error(`Value must be an instance of BytesValue. Received: '${value})'`)
@@ -32,6 +43,13 @@ class ContinueRequestParameters {
32
43
  return this
33
44
  }
34
45
 
46
+ /**
47
+ * Sets the cookies for the request.
48
+ *
49
+ * @param {Header[]} cookieHeaders - An array of cookie headers.
50
+ * @returns {continueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
51
+ * @throws {Error} - If a cookie header is not an instance of Header.
52
+ */
35
53
  cookies(cookieHeaders) {
36
54
  const cookies = []
37
55
  cookieHeaders.forEach((header) => {
@@ -45,6 +63,13 @@ class ContinueRequestParameters {
45
63
  return this
46
64
  }
47
65
 
66
+ /**
67
+ * Sets the headers for the request.
68
+ *
69
+ * @param {Header[]} headers - An array of Header objects.
70
+ * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
71
+ * @throws {Error} - If the header value is not an instance of Header.
72
+ */
48
73
  headers(headers) {
49
74
  const headerList = []
50
75
  headers.forEach((header) => {
@@ -58,6 +83,13 @@ class ContinueRequestParameters {
58
83
  return this
59
84
  }
60
85
 
86
+ /**
87
+ * Sets the HTTP method for the request.
88
+ *
89
+ * @param {string} method - The HTTP method to be set.
90
+ * @returns {ContinueRequestParameters} - The updated `continueRequestParameters` object.
91
+ * @throws {Error} - If the method parameter is not a string.
92
+ */
61
93
  method(method) {
62
94
  if (typeof method !== 'string') {
63
95
  throw new Error(`Http method must be a string. Received: '${method})'`)
@@ -66,6 +98,13 @@ class ContinueRequestParameters {
66
98
  return this
67
99
  }
68
100
 
101
+ /**
102
+ * Sets the URL for the request.
103
+ *
104
+ * @param {string} url - The URL to set for the request.
105
+ * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
106
+ * @throws {Error} - If the url parameter is not a string.
107
+ */
69
108
  url(url) {
70
109
  if (typeof url !== 'string') {
71
110
  throw new Error(`Url must be a string. Received:'${url}'`)
@@ -17,6 +17,10 @@
17
17
 
18
18
  const { Header } = require('./networkTypes')
19
19
 
20
+ /**
21
+ * Represents the parameters for a continue response.
22
+ * Described in https://w3c.github.io/webdriver-bidi/#command-network-continueResponse.
23
+ */
20
24
  class ContinueResponseParameters {
21
25
  #map = new Map()
22
26
 
@@ -24,6 +28,13 @@ class ContinueResponseParameters {
24
28
  this.#map.set('request', request)
25
29
  }
26
30
 
31
+ /**
32
+ * Sets the cookies for the response.
33
+ *
34
+ * @param {Header[]} cookieHeaders - The array of cookie headers.
35
+ * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
36
+ * @throws {Error} - If the cookieHeader is not an instance of Header.
37
+ */
27
38
  cookies(cookieHeaders) {
28
39
  const cookies = []
29
40
  cookieHeaders.forEach((header) => {
@@ -37,6 +48,14 @@ class ContinueResponseParameters {
37
48
  return this
38
49
  }
39
50
 
51
+ /**
52
+ * Sets the credentials for authentication.
53
+ *
54
+ * @param {string} username - The username for authentication.
55
+ * @param {string} password - The password for authentication.
56
+ * @returns {ContinueResponseParameters} The current instance of the ContinueResponseParameters for chaining.
57
+ * @throws {Error} If username or password is not a string.
58
+ */
40
59
  credentials(username, password) {
41
60
  if (typeof username !== 'string') {
42
61
  throw new Error(`Username must be a string. Received:'${username}'`)
@@ -51,6 +70,13 @@ class ContinueResponseParameters {
51
70
  return this
52
71
  }
53
72
 
73
+ /**
74
+ * Sets the headers for the response.
75
+ *
76
+ * @param {Header[]} headers - An array of Header objects representing the headers.
77
+ * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
78
+ * @throws {Error} - If the header value is not an instance of Header.
79
+ */
54
80
  headers(headers) {
55
81
  const headerList = []
56
82
  headers.forEach((header) => {
@@ -64,6 +90,13 @@ class ContinueResponseParameters {
64
90
  return this
65
91
  }
66
92
 
93
+ /**
94
+ * Sets the reason phrase for the response.
95
+ *
96
+ * @param {string} reasonPhrase - The reason phrase for the response.
97
+ * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
98
+ * @throws {Error} - If the reason phrase is not a string.
99
+ */
67
100
  reasonPhrase(reasonPhrase) {
68
101
  if (typeof reasonPhrase !== 'string') {
69
102
  throw new Error(`Reason phrase must be a string. Received: '${reasonPhrase})'`)
@@ -72,6 +105,13 @@ class ContinueResponseParameters {
72
105
  return this
73
106
  }
74
107
 
108
+ /**
109
+ * Sets the status code for the response.
110
+ *
111
+ * @param {number} statusCode - The status code to set.
112
+ * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
113
+ * @throws {Error} - If the `statusCode` parameter is not an integer.
114
+ */
75
115
  statusCode(statusCode) {
76
116
  if (!Number.isInteger(statusCode)) {
77
117
  throw new Error(`Status must be an integer. Received:'${statusCode}'`)
@@ -17,14 +17,31 @@
17
17
 
18
18
  const { SameSite, BytesValue } = require('./networkTypes')
19
19
 
20
+ /**
21
+ * Represents a filter for fetching cookies.
22
+ * Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies
23
+ */
20
24
  class CookieFilter {
21
25
  #map = new Map()
22
26
 
27
+ /**
28
+ * Sets the name of the cookie.
29
+ *
30
+ * @param {string} name - The name of the cookie.
31
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
32
+ */
23
33
  name(name) {
24
34
  this.#map.set('name', name)
25
35
  return this
26
36
  }
27
37
 
38
+ /**
39
+ * Sets the value of the cookie.
40
+ *
41
+ * @param {BytesValue} value - The value to be set. Must be an instance of BytesValue.
42
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
43
+ * @throws {Error} - If the value is not an instance of BytesValue.
44
+ */
28
45
  value(value) {
29
46
  if (!(value instanceof BytesValue)) {
30
47
  throw new Error(`Value must be an instance of BytesValue. Received:'${value}'`)
@@ -33,31 +50,68 @@ class CookieFilter {
33
50
  return this
34
51
  }
35
52
 
53
+ /**
54
+ * Sets the domain for the cookie.
55
+ *
56
+ * @param {string} domain - The domain to set.
57
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
58
+ */
36
59
  domain(domain) {
37
60
  this.#map.set('domain', domain)
38
61
  return this
39
62
  }
40
63
 
64
+ /**
65
+ * Sets the url path for the cookie to be fetched.
66
+ *
67
+ * @param {string} path - The url path for the cookie to be fetched.
68
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
69
+ */
41
70
  path(path) {
42
71
  this.#map.set('path', path)
43
72
  return this
44
73
  }
45
74
 
75
+ /**
76
+ * Sets the size of the cookie to be fetched.
77
+ *
78
+ * @param {number} size - The size of the cookie.
79
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
80
+ */
46
81
  size(size) {
47
82
  this.#map.set('size', size)
48
83
  return this
49
84
  }
50
85
 
86
+ /**
87
+ * Sets the `httpOnly` flag for the cookie filter.
88
+ *
89
+ * @param {boolean} httpOnly - The value to set for the `httpOnly` flag.
90
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
91
+ */
51
92
  httpOnly(httpOnly) {
52
93
  this.#map.set('httpOnly', httpOnly)
53
94
  return this
54
95
  }
55
96
 
97
+ /**
98
+ * Sets the flag to fetch secure cookies.
99
+ *
100
+ * @param {boolean} secure - Whether the cookie fetched should be secure only or not.
101
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
102
+ */
56
103
  secure(secure) {
57
104
  this.#map.set('secure', secure)
58
105
  return this
59
106
  }
60
107
 
108
+ /**
109
+ * Sets the SameSite attribute for the cookie.
110
+ *
111
+ * @param {SameSite} sameSite - The SameSite value to be set for the cookie.
112
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
113
+ * @throws {Error} - If the provided sameSite value is not an instance of SameSite.
114
+ */
61
115
  sameSite(sameSite) {
62
116
  if (!(sameSite instanceof SameSite)) {
63
117
  throw new Error(`Params must be a value in SameSite. Received:'${sameSite}'`)
@@ -66,6 +120,12 @@ class CookieFilter {
66
120
  return this
67
121
  }
68
122
 
123
+ /**
124
+ * Sets the expiry value.
125
+ *
126
+ * @param {number} expiry - The expiry value.
127
+ * @returns {CookieFilter} - The updated CookieFilter instance for chaining.
128
+ */
69
129
  expiry(expiry) {
70
130
  this.#map.set('expiry', expiry)
71
131
  return this
@@ -0,0 +1,73 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ /**
19
+ * Represents a set of parameters for creating a context.
20
+ * Described in https://w3c.github.io/webdriver-bidi/#command-browsingContext-create.
21
+ */
22
+ class CreateContextParameters {
23
+ #map = new Map()
24
+
25
+ /**
26
+ * Sets the reference context.
27
+ * @param {string} id - The ID of the reference context.
28
+ * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.
29
+ * @throws {Error} - If the provided ID is not a string.
30
+ */
31
+ referenceContext(id) {
32
+ if (typeof id !== 'string') {
33
+ throw new Error(`ReferenceContext must be string. Received:'${id}'`)
34
+ }
35
+ this.#map.set('referenceContext', id)
36
+ return this
37
+ }
38
+
39
+ /**
40
+ * Sets the background parameter.
41
+ *
42
+ * @param {boolean} background - The background value to set.
43
+ * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.
44
+ * @throws {Error} - If the background parameter is not a boolean.
45
+ */
46
+ background(background) {
47
+ if (typeof background !== 'boolean') {
48
+ throw new Error(`Background must be boolean. Received:'${background}'`)
49
+ }
50
+ this.#map.set('background', background)
51
+ return this
52
+ }
53
+
54
+ /**
55
+ * Sets the user context.
56
+ * @param {string} userContext - The user context to set.
57
+ * @returns {CreateContextParameters} - The updated instance of CreateContextParameters for chaining.
58
+ * @throws {Error} - If the userContext parameter is not a string.
59
+ */
60
+ userContext(userContext) {
61
+ if (typeof userContext !== 'string') {
62
+ throw new Error(`UserContext must be string. Received:'${userContext}'`)
63
+ }
64
+ this.#map.set('userContext', userContext)
65
+ return this
66
+ }
67
+
68
+ asMap() {
69
+ return this.#map
70
+ }
71
+ }
72
+
73
+ module.exports = { CreateContextParameters }
@@ -15,11 +15,20 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
+ /**
19
+ * Represents the type of script evaluation result.
20
+ * Described in https://w3c.github.io/webdriver-bidi/#type-script-EvaluateResult.
21
+ * @enum {string}
22
+ */
18
23
  const EvaluateResultType = {
19
24
  SUCCESS: 'success',
20
25
  EXCEPTION: 'exception',
21
26
  }
22
27
 
28
+ /**
29
+ * Represents a successful evaluation result.
30
+ * @class
31
+ */
23
32
  class EvaluateResultSuccess {
24
33
  constructor(realmId, value) {
25
34
  this.resultType = EvaluateResultType.SUCCESS
@@ -28,6 +37,10 @@ class EvaluateResultSuccess {
28
37
  }
29
38
  }
30
39
 
40
+ /**
41
+ * Represents an exception that occurred during evaluation of a result.
42
+ * @class
43
+ */
31
44
  class EvaluateResultException {
32
45
  constructor(realmId, exceptionDetails) {
33
46
  this.resultType = EvaluateResultType.EXCEPTION
@@ -36,6 +49,10 @@ class EvaluateResultException {
36
49
  }
37
50
  }
38
51
 
52
+ /**
53
+ * Represents details of an exception.
54
+ * @class
55
+ */
39
56
  class ExceptionDetails {
40
57
  constructor(exceptionDetails) {
41
58
  this.columnNumber = 'columnNumber' in exceptionDetails ? exceptionDetails['columnNumber'] : null
package/bidi/index.js CHANGED
@@ -15,7 +15,6 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- // eslint-disable-next-line node/no-missing-require
19
18
  const { EventEmitter } = require('node:events')
20
19
  const WebSocket = require('ws')
21
20
 
package/bidi/input.js CHANGED
@@ -20,6 +20,10 @@
20
20
  const { WebElement } = require('../lib/webdriver')
21
21
  const { RemoteReferenceType, ReferenceValue } = require('./protocolValue')
22
22
 
23
+ /**
24
+ * Represents commands and events related to the Input module (simulated user input).
25
+ * Described in https://w3c.github.io/webdriver-bidi/#module-input.
26
+ */
23
27
  class Input {
24
28
  constructor(driver) {
25
29
  this._driver = driver
@@ -33,6 +37,13 @@ class Input {
33
37
  this.bidi = await this._driver.getBidi()
34
38
  }
35
39
 
40
+ /**
41
+ * Performs the specified actions on the given browsing context.
42
+ *
43
+ * @param {string} browsingContextId - The ID of the browsing context.
44
+ * @param {Array} actions - The actions to be performed.
45
+ * @returns {Promise} A promise that resolves with the response from the server.
46
+ */
36
47
  async perform(browsingContextId, actions) {
37
48
  const _actions = await updateActions(actions)
38
49
 
@@ -44,11 +55,15 @@ class Input {
44
55
  },
45
56
  }
46
57
 
47
- let response = await this.bidi.send(command)
48
-
49
- return response
58
+ return await this.bidi.send(command)
50
59
  }
51
60
 
61
+ /**
62
+ * Resets the input state in the specified browsing context.
63
+ *
64
+ * @param {string} browsingContextId - The ID of the browsing context.
65
+ * @returns {Promise} A promise that resolves when the release actions are sent.
66
+ */
52
67
  async release(browsingContextId) {
53
68
  const command = {
54
69
  method: 'input.releaseActions',
@@ -59,6 +74,15 @@ class Input {
59
74
  return await this.bidi.send(command)
60
75
  }
61
76
 
77
+ /**
78
+ * Sets the files property of a given input element.
79
+ *
80
+ * @param {string} browsingContextId - The ID of the browsing context.
81
+ * @param {string | ReferenceValue} element - The ID of the element or a ReferenceValue object representing the element.
82
+ * @param {string | string[]} files - The file path or an array of file paths to be set.
83
+ * @throws {Error} If the element is not a string or a ReferenceValue.
84
+ * @returns {Promise<void>} A promise that resolves when the files are set.
85
+ */
62
86
  async setFiles(browsingContextId, element, files) {
63
87
  if (typeof element !== 'string' && !(element instanceof ReferenceValue)) {
64
88
  throw Error(`Pass in a WebElement id as a string or a ReferenceValue. Received: ${element}`)
@@ -15,6 +15,10 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
+ /**
19
+ * Represents the different phases of intercepting network requests and responses.
20
+ * @enum {string}
21
+ */
18
22
  const InterceptPhase = {
19
23
  BEFORE_REQUEST_SENT: 'beforeRequestSent',
20
24
  RESPONSE_STARTED: 'responseStarted',