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
package/CHANGES.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 4.20.0
2
+
3
+ - Add CDP for Chrome 124 and remove 121
4
+ - [bidi] Update capture screenshot APIs to include all parameters and remove scroll parameter (
5
+ #13744)
6
+ - [bidi] Implement functionality to retrieve all top-level browsing contexts
7
+ - Set browserName by default when browserOptions are used
8
+ - Implement fullPageScreenshot functionality for Firefox (#13301)
9
+ - Nightly JS builds are now pushed to GitHub packages
10
+ - Making Selenium Manager a thin wrapper (#13853)
11
+ - This change has been made to make it easier to maintain and improve, the interface has
12
+ changed and if users were invoking it, they might experience issues. Selenium Manager is
13
+ still in beta and these type of changes are expected.
14
+ - [bidi] Update browsing context create method (#13766)
15
+
1
16
  ## 4.19.0
2
17
 
3
18
  - Add CDP for Chrome 123 and remove 120
@@ -29,6 +29,13 @@ class AddInterceptParameters {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * Adds a URL pattern to intercept.
34
+ *
35
+ * @param {UrlPattern} pattern - The URL pattern to add.
36
+ * @returns {AddInterceptParameters} - Returns the current instance of the class AddInterceptParameters for chaining.
37
+ * @throws {Error} - Throws an error if the pattern is not an instance of UrlPattern.
38
+ */
32
39
  urlPattern(pattern) {
33
40
  if (!(pattern instanceof UrlPattern)) {
34
41
  throw new Error(`Pattern must be an instance of UrlPattern. Received: '${pattern})'`)
@@ -37,6 +44,13 @@ class AddInterceptParameters {
37
44
  return this
38
45
  }
39
46
 
47
+ /**
48
+ * Adds array of URL patterns to intercept.
49
+ *
50
+ * @param {UrlPattern[]} patterns - An array of UrlPattern instances representing the URL patterns to intercept.
51
+ * @returns {AddInterceptParameters} - Returns the instance of AddInterceptParameters for chaining.
52
+ * @throws {Error} - Throws an error if the pattern is not an instance of UrlPattern.
53
+ */
40
54
  urlPatterns(patterns) {
41
55
  patterns.forEach((pattern) => {
42
56
  if (!(pattern instanceof UrlPattern)) {
@@ -47,8 +61,15 @@ class AddInterceptParameters {
47
61
  return this
48
62
  }
49
63
 
64
+ /**
65
+ * Adds string URL to intercept.
66
+ *
67
+ * @param {string} pattern - The URL pattern to be added.
68
+ * @returns {AddInterceptParameters} - Returns the instance of AddInterceptParameters for chaining..
69
+ * @throws {Error} - If the pattern is not an instance of String.
70
+ */
50
71
  urlStringPattern(pattern) {
51
- if (!(pattern instanceof String)) {
72
+ if (typeof pattern !== 'string') {
52
73
  throw new Error(`Pattern must be an instance of String. Received:'${pattern}'`)
53
74
  }
54
75
 
@@ -56,9 +77,14 @@ class AddInterceptParameters {
56
77
  return this
57
78
  }
58
79
 
80
+ /**
81
+ * Adds array of string URLs to intercept.
82
+ * @param {string[]} patterns - An array of URL string patterns.
83
+ * @returns {this} - Returns the instance of AddInterceptParameters for chaining.
84
+ */
59
85
  urlStringPatterns(patterns) {
60
86
  patterns.forEach((pattern) => {
61
- if (!(pattern instanceof String)) {
87
+ if (typeof pattern !== 'string') {
62
88
  throw new Error(`Pattern must be an instance of String. Received:'${pattern}'`)
63
89
  }
64
90
  this.#urlPatterns.push({ type: 'string', pattern: pattern })
package/bidi/browser.js CHANGED
@@ -15,6 +15,10 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
+ /**
19
+ * Represents the commands and events under Browser Module.
20
+ * Described in https://w3c.github.io/webdriver-bidi/#module-browser
21
+ */
18
22
  class Browser {
19
23
  constructor(driver) {
20
24
  this._driver = driver
@@ -28,6 +32,10 @@ class Browser {
28
32
  this.bidi = await this._driver.getBidi()
29
33
  }
30
34
 
35
+ /**
36
+ * Creates a new user context.
37
+ * @returns {Promise<string>} A promise that resolves to the user context id.
38
+ */
31
39
  async createUserContext() {
32
40
  const command = {
33
41
  method: 'browser.createUserContext',
@@ -39,6 +47,10 @@ class Browser {
39
47
  return response.result.userContext
40
48
  }
41
49
 
50
+ /**
51
+ * Gets the list of all user contexts.
52
+ * @returns {Promise<string[]>} A promise that resolves to an array of user context ids.
53
+ */
42
54
  async getUserContexts() {
43
55
  const command = {
44
56
  method: 'browser.getUserContexts',
@@ -58,6 +70,11 @@ class Browser {
58
70
  return userContexts
59
71
  }
60
72
 
73
+ /**
74
+ * Removes a user context.
75
+ * @param {string} userContext The user context id to be removed.
76
+ * @returns {Promise<void>}
77
+ */
61
78
  async removeUserContext(userContext) {
62
79
  const command = {
63
80
  method: 'browser.removeUserContext',
@@ -19,7 +19,13 @@ const { InvalidArgumentError, NoSuchFrameError } = require('../lib/error')
19
19
  const { BrowsingContextInfo } = require('./browsingContextTypes')
20
20
  const { SerializationOptions, ReferenceValue, RemoteValue } = require('./protocolValue')
21
21
  const { WebElement } = require('../lib/webdriver')
22
+ const { CaptureScreenshotParameters } = require('./captureScreenshotParameters')
23
+ const { CreateContextParameters } = require('./createContextParameters')
22
24
 
25
+ /**
26
+ * Represents the locator to locate nodes in the browsing context.
27
+ * Described in https://w3c.github.io/webdriver-bidi/#type-browsingContext-Locator.
28
+ */
23
29
  class Locator {
24
30
  static Type = Object.freeze({
25
31
  CSS: 'css',
@@ -41,14 +47,35 @@ class Locator {
41
47
  this.#maxDepth = maxDepth
42
48
  }
43
49
 
50
+ /**
51
+ * Creates a new Locator object with CSS selector type.
52
+ *
53
+ * @param {string} value - The CSS selector value.
54
+ * @returns {Locator} A new Locator object with CSS selector type.
55
+ */
44
56
  static css(value) {
45
57
  return new Locator(Locator.Type.CSS, value)
46
58
  }
47
59
 
60
+ /**
61
+ * Creates a new Locator object with the given XPath value.
62
+ *
63
+ * @param {string} value - The XPath value.
64
+ * @returns {Locator} A new Locator object.
65
+ */
48
66
  static xpath(value) {
49
67
  return new Locator(Locator.Type.XPATH, value)
50
68
  }
51
69
 
70
+ /**
71
+ * Creates a new Locator object with the specified inner text value.
72
+ *
73
+ * @param {string} value - The inner text value to locate.
74
+ * @param {boolean|undefined} [ignoreCase] - Whether to ignore the case when matching the inner text value.
75
+ * @param {string|undefined} [matchType] - The type of matching to perform (full or partial).
76
+ * @param {number|undefined} [maxDepth] - The maximum depth to search for the inner text value.
77
+ * @returns {Locator} A new Locator object with the specified inner text value.
78
+ */
52
79
  static innerText(value, ignoreCase = undefined, matchType = undefined, maxDepth = undefined) {
53
80
  return new Locator(Locator.Type.INNER_TEXT, value, ignoreCase, matchType, maxDepth)
54
81
  }
@@ -66,6 +93,12 @@ class Locator {
66
93
  }
67
94
  }
68
95
 
96
+ /**
97
+ * Represents the contains under BrowsingContext module commands.
98
+ * Described in https://w3c.github.io/webdriver-bidi/#module-browsingContext
99
+ * Each browsing context command requires a browsing context id.
100
+ * Hence, this class represent browsing context lifecycle.
101
+ */
69
102
  class BrowsingContext {
70
103
  constructor(driver) {
71
104
  this._driver = driver
@@ -78,11 +111,19 @@ class BrowsingContext {
78
111
  return this._id
79
112
  }
80
113
 
81
- async init({ browsingContextId, type, referenceContext }) {
114
+ async init({ browsingContextId = undefined, type = undefined, createParameters = undefined }) {
82
115
  if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
83
116
  throw Error('WebDriver instance must support BiDi protocol')
84
117
  }
85
118
 
119
+ if (browsingContextId === undefined && type === undefined && createParameters === undefined) {
120
+ throw Error('Either BrowsingContextId or Type or CreateParameters must be provided')
121
+ }
122
+
123
+ if (type === undefined && createParameters !== undefined) {
124
+ throw Error('Type must be provided with CreateParameters')
125
+ }
126
+
86
127
  if (type !== undefined && !['window', 'tab'].includes(type)) {
87
128
  throw Error(`Valid types are 'window' & 'tab'. Received: ${type}`)
88
129
  }
@@ -90,22 +131,33 @@ class BrowsingContext {
90
131
  this.bidi = await this._driver.getBidi()
91
132
  this._id =
92
133
  browsingContextId === undefined
93
- ? (await this.create(type, referenceContext))['result']['context']
134
+ ? (await this.create(type, createParameters))['result']['context']
94
135
  : browsingContextId
95
136
  }
96
137
 
97
138
  /**
98
- * Creates a browsing context for the given type and referenceContext
139
+ * Creates a browsing context for the given type with the given parameters
99
140
  */
100
- async create(type, referenceContext) {
141
+ async create(type, createParameters = undefined) {
142
+ if (createParameters !== undefined && (!createParameters) instanceof CreateContextParameters) {
143
+ throw Error(`Pass in the instance of CreateContextParameters. Received: ${createParameters}`)
144
+ }
145
+
146
+ let parameters = new Map()
147
+ parameters.set('type', type)
148
+
149
+ if (createParameters !== undefined) {
150
+ createParameters.asMap().forEach((value, key) => {
151
+ parameters.set(key, value)
152
+ })
153
+ }
154
+
101
155
  const params = {
102
156
  method: 'browsingContext.create',
103
- params: {
104
- type: type,
105
- referenceContext: referenceContext,
106
- },
157
+ params: Object.fromEntries(parameters),
107
158
  }
108
- return await this.bidi.send(params)
159
+ const res = await this.bidi.send(params)
160
+ return res
109
161
  }
110
162
 
111
163
  /**
@@ -153,6 +205,27 @@ class BrowsingContext {
153
205
  return new BrowsingContextInfo(result['context'], result['url'], result['children'], result['parent'])
154
206
  }
155
207
 
208
+ /**
209
+ * @returns {Promise<Array<BrowsingContextInfo>>} A Promise that resolves to an array of BrowsingContextInfo objects representing the top-level browsing contexts.
210
+ */
211
+ async getTopLevelContexts() {
212
+ const params = {
213
+ method: 'browsingContext.getTree',
214
+ params: {},
215
+ }
216
+
217
+ let result = await this.bidi.send(params)
218
+ if ('error' in result) {
219
+ throw Error(result['error'])
220
+ }
221
+
222
+ const contexts = result['result']['contexts']
223
+ const browsingContexts = contexts.map((context) => {
224
+ return new BrowsingContextInfo(context['id'], context['url'], context['children'], context['parent'])
225
+ })
226
+ return browsingContexts
227
+ }
228
+
156
229
  /**
157
230
  * Closes the browsing context
158
231
  * @returns {Promise<void>}
@@ -203,12 +276,34 @@ class BrowsingContext {
203
276
  return new PrintResult(response.result.data)
204
277
  }
205
278
 
206
- async captureScreenshot() {
279
+ /**
280
+ * Captures a screenshot of the browsing context.
281
+ *
282
+ * @param {CaptureScreenshotParameters|undefined} [captureScreenshotParameters] - Optional parameters for capturing the screenshot.
283
+ * @returns {Promise<string>} - A promise that resolves to the base64-encoded string representation of the captured screenshot.
284
+ * @throws {InvalidArgumentError} - If the provided captureScreenshotParameters is not an instance of CaptureScreenshotParameters.
285
+ */
286
+ async captureScreenshot(captureScreenshotParameters = undefined) {
287
+ if (
288
+ captureScreenshotParameters !== undefined &&
289
+ !(captureScreenshotParameters instanceof CaptureScreenshotParameters)
290
+ ) {
291
+ throw new InvalidArgumentError(
292
+ `Pass in a CaptureScreenshotParameters object. Received: ${captureScreenshotParameters}`,
293
+ )
294
+ }
295
+
296
+ const screenshotParams = new Map()
297
+ screenshotParams.set('context', this._id)
298
+ if (captureScreenshotParameters !== undefined) {
299
+ captureScreenshotParameters.asMap().forEach((value, key) => {
300
+ screenshotParams.set(key, value)
301
+ })
302
+ }
303
+
207
304
  let params = {
208
305
  method: 'browsingContext.captureScreenshot',
209
- params: {
210
- context: this._id,
211
- },
306
+ params: Object.fromEntries(screenshotParams),
212
307
  }
213
308
 
214
309
  const response = await this.bidi.send(params)
@@ -231,15 +326,18 @@ class BrowsingContext {
231
326
  },
232
327
  }
233
328
 
234
- console.log(JSON.stringify(params))
235
-
236
329
  const response = await this.bidi.send(params)
237
- console.log(JSON.stringify(response))
238
330
  this.checkErrorInScreenshot(response)
239
331
  return response['result']['data']
240
332
  }
241
333
 
242
- async captureElementScreenshot(sharedId, handle = undefined, scrollIntoView = undefined) {
334
+ /**
335
+ * Captures a screenshot of a specific element within the browsing context.
336
+ * @param {string} sharedId - The shared ID of the element to capture.
337
+ * @param {string} [handle] - The handle of the element to capture (optional).
338
+ * @returns {Promise<string>} A promise that resolves to the base64-encoded screenshot data.
339
+ */
340
+ async captureElementScreenshot(sharedId, handle = undefined) {
243
341
  let params = {
244
342
  method: 'browsingContext.captureScreenshot',
245
343
  params: {
@@ -250,7 +348,6 @@ class BrowsingContext {
250
348
  sharedId: sharedId,
251
349
  handle: handle,
252
350
  },
253
- scrollIntoView: scrollIntoView,
254
351
  },
255
352
  },
256
353
  }
@@ -274,6 +371,11 @@ class BrowsingContext {
274
371
  }
275
372
  }
276
373
 
374
+ /**
375
+ * Activates and focuses the top-level browsing context.
376
+ * @returns {Promise<void>} A promise that resolves when the browsing context is activated.
377
+ * @throws {Error} If there is an error while activating the browsing context.
378
+ */
277
379
  async activate() {
278
380
  const params = {
279
381
  method: 'browsingContext.activate',
@@ -288,6 +390,13 @@ class BrowsingContext {
288
390
  }
289
391
  }
290
392
 
393
+ /**
394
+ * Handles a user prompt in the browsing context.
395
+ *
396
+ * @param {boolean} [accept] - Optional. Indicates whether to accept or dismiss the prompt.
397
+ * @param {string} [userText] - Optional. The text to enter.
398
+ * @throws {Error} If an error occurs while handling the user prompt.
399
+ */
291
400
  async handleUserPrompt(accept = undefined, userText = undefined) {
292
401
  const params = {
293
402
  method: 'browsingContext.handleUserPrompt',
@@ -304,6 +413,15 @@ class BrowsingContext {
304
413
  }
305
414
  }
306
415
 
416
+ /**
417
+ * Reloads the current browsing context.
418
+ *
419
+ * @param {boolean} [ignoreCache] - Whether to ignore the cache when reloading.
420
+ * @param {string} [readinessState] - The readiness state to wait for before returning.
421
+ * Valid readiness states are 'none', 'interactive', and 'complete'.
422
+ * @returns {Promise<NavigateResult>} - A promise that resolves to the result of the reload operation.
423
+ * @throws {Error} - If an invalid readiness state is provided.
424
+ */
307
425
  async reload(ignoreCache = undefined, readinessState = undefined) {
308
426
  if (readinessState !== undefined && !['none', 'interactive', 'complete'].includes(readinessState)) {
309
427
  throw Error(`Valid readiness states are 'none', 'interactive' & 'complete'. Received: ${readinessState}`)
@@ -322,6 +440,13 @@ class BrowsingContext {
322
440
  return new NavigateResult(navigateResult['url'], navigateResult['navigation'])
323
441
  }
324
442
 
443
+ /**
444
+ * Sets the viewport size and device pixel ratio for the browsing context.
445
+ * @param {number} width - The width of the viewport.
446
+ * @param {number} height - The height of the viewport.
447
+ * @param {number} [devicePixelRatio] - The device pixel ratio (optional)
448
+ * @throws {Error} If an error occurs while setting the viewport.
449
+ */
325
450
  async setViewport(width, height, devicePixelRatio = undefined) {
326
451
  const params = {
327
452
  method: 'browsingContext.setViewport',
@@ -337,6 +462,12 @@ class BrowsingContext {
337
462
  }
338
463
  }
339
464
 
465
+ /**
466
+ * Traverses the browsing context history by a given delta.
467
+ *
468
+ * @param {number} delta - The delta value to traverse the history. A positive value moves forward, while a negative value moves backward.
469
+ * @returns {Promise<void>} - A promise that resolves when the history traversal is complete.
470
+ */
340
471
  async traverseHistory(delta) {
341
472
  const params = {
342
473
  method: 'browsingContext.traverseHistory',
@@ -348,14 +479,38 @@ class BrowsingContext {
348
479
  await this.bidi.send(params)
349
480
  }
350
481
 
482
+ /**
483
+ * Moves the browsing context forward by one step in the history.
484
+ * @returns {Promise<void>} A promise that resolves when the browsing context has moved forward.
485
+ */
351
486
  async forward() {
352
487
  await this.traverseHistory(1)
353
488
  }
354
489
 
490
+ /**
491
+ * Navigates the browsing context to the previous page in the history.
492
+ * @returns {Promise<void>} A promise that resolves when the navigation is complete.
493
+ */
355
494
  async back() {
356
495
  await this.traverseHistory(-1)
357
496
  }
358
497
 
498
+ /**
499
+ * Locates nodes in the browsing context.
500
+ *
501
+ * @param {Locator} locator - The locator object used to locate the nodes.
502
+ * @param {number} [maxNodeCount] - The maximum number of nodes to locate (optional).
503
+ * @param {string} [ownership] - The ownership type of the nodes (optional).
504
+ * @param {string} [sandbox] - The sandbox name for locating nodes (optional).
505
+ * @param {SerializationOptions} [serializationOptions] - The serialization options for locating nodes (optional).
506
+ * @param {ReferenceValue[]} [startNodes] - The array of start nodes for locating nodes (optional).
507
+ * @returns {Promise<RemoteValue[]>} - A promise that resolves to the arrays of located nodes.
508
+ * @throws {Error} - If the locator is not an instance of Locator.
509
+ * @throws {Error} - If the serializationOptions is provided but not an instance of SerializationOptions.
510
+ * @throws {Error} - If the ownership is provided but not 'root' or 'none'.
511
+ * @throws {Error} - If the startNodes is provided but not an array of ReferenceValue objects.
512
+ * @throws {Error} - If any of the startNodes is not an instance of ReferenceValue.
513
+ */
359
514
  async locateNodes(
360
515
  locator,
361
516
  maxNodeCount = undefined,
@@ -415,6 +570,16 @@ class BrowsingContext {
415
570
  return remoteValues
416
571
  }
417
572
 
573
+ /**
574
+ * Locates a single node in the browsing context.
575
+ *
576
+ * @param {Locator} locator - The locator used to find the node.
577
+ * @param {string} [ownership] - The ownership of the node (optional).
578
+ * @param {string} [sandbox] - The sandbox of the node (optional).
579
+ * @param {SerializationOptions} [serializationOptions] - The serialization options for the node (optional).
580
+ * @param {Array} [startNodes] - The starting nodes for the search (optional).
581
+ * @returns {Promise<RemoteValue>} - A promise that resolves to the located node.
582
+ */
418
583
  async locateNode(
419
584
  locator,
420
585
  ownership = undefined,
@@ -442,26 +607,44 @@ class BrowsingContext {
442
607
  }
443
608
  }
444
609
 
610
+ /**
611
+ * Represents the result of a navigation operation.
612
+ */
445
613
  class NavigateResult {
446
614
  constructor(url, navigationId) {
447
615
  this._url = url
448
616
  this._navigationId = navigationId
449
617
  }
450
618
 
619
+ /**
620
+ * Gets the URL of the navigated page.
621
+ * @returns {string} The URL of the navigated page.
622
+ */
451
623
  get url() {
452
624
  return this._url
453
625
  }
454
626
 
627
+ /**
628
+ * Gets the ID of the navigation operation.
629
+ * @returns {number} The ID of the navigation operation.
630
+ */
455
631
  get navigationId() {
456
632
  return this._navigationId
457
633
  }
458
634
  }
459
635
 
636
+ /**
637
+ * Represents a print result.
638
+ */
460
639
  class PrintResult {
461
640
  constructor(data) {
462
641
  this._data = data
463
642
  }
464
643
 
644
+ /**
645
+ * Gets the data associated with the print result.
646
+ * @returns {any} The data associated with the print result.
647
+ */
465
648
  get data() {
466
649
  return this._data
467
650
  }
@@ -472,18 +655,17 @@ class PrintResult {
472
655
  * @param driver
473
656
  * @param browsingContextId The browsing context of current window/tab
474
657
  * @param type "window" or "tab"
475
- * @param referenceContext To get a browsing context for this reference if passed
658
+ * @param createParameters The parameters for creating a new browsing context
476
659
  * @returns {Promise<BrowsingContext>}
477
660
  */
478
- async function getBrowsingContextInstance(driver, { browsingContextId, type, referenceContext }) {
661
+ async function getBrowsingContextInstance(
662
+ driver,
663
+ { browsingContextId = undefined, type = undefined, createParameters = undefined },
664
+ ) {
479
665
  let instance = new BrowsingContext(driver)
480
- await instance.init({ browsingContextId, type, referenceContext })
666
+ await instance.init({ browsingContextId, type, createParameters })
481
667
  return instance
482
668
  }
483
669
 
484
- /**
485
- * API
486
- * @type {function(*, {*,*,*}): Promise<BrowsingContext>}
487
- */
488
670
  module.exports = getBrowsingContextInstance
489
671
  module.exports.Locator = Locator
@@ -17,6 +17,12 @@
17
17
 
18
18
  const { BrowsingContextInfo, NavigationInfo } = require('./browsingContextTypes')
19
19
 
20
+ /**
21
+ * Represents a browsing context related events.
22
+ * Described in https://w3c.github.io/webdriver-bidi/#module-contexts-events.
23
+ * While BrowsingContext class represents a browsing context lifecycle and related commands.
24
+ * This class is specific to listening to events. Events can be subscribed to multiple browsing contexts or all of them.
25
+ */
20
26
  class BrowsingContextInspector {
21
27
  constructor(driver, browsingContextIds) {
22
28
  this._driver = driver
@@ -27,34 +33,79 @@ class BrowsingContextInspector {
27
33
  this.bidi = await this._driver.getBidi()
28
34
  }
29
35
 
36
+ /**
37
+ * Subscribes to the 'browsingContext.contextCreated' event.
38
+ * @param {Function} callback - The callback function to handle the event.
39
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
40
+ */
30
41
  async onBrowsingContextCreated(callback) {
31
42
  await this.subscribeAndHandleEvent('browsingContext.contextCreated', callback)
32
43
  }
33
44
 
45
+ /**
46
+ * Subscribes to the 'browsingContext.contextDestroyed' event.
47
+ * @param {Function} callback - The callback function to handle the event.
48
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
49
+ */
34
50
  async onBrowsingContextDestroyed(callback) {
35
51
  await this.subscribeAndHandleEvent('browsingContext.contextDestroyed', callback)
36
52
  }
37
53
 
54
+ /**
55
+ * Subscribe to the 'browsingContext.navigationStarted' event.
56
+ * @param {Function} callback - The callback function to handle the event.
57
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
58
+ */
38
59
  async onNavigationStarted(callback) {
39
60
  await this.subscribeAndHandleEvent('browsingContext.navigationStarted', callback)
40
61
  }
41
62
 
63
+ /**
64
+ * Subscribes to the 'browsingContext.fragmentNavigated' event.
65
+ *
66
+ * @param {Function} callback - The callback function to handle the event.
67
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
68
+ */
42
69
  async onFragmentNavigated(callback) {
43
70
  await this.subscribeAndHandleEvent('browsingContext.fragmentNavigated', callback)
44
71
  }
45
72
 
73
+ /**
74
+ * Subscribes to the 'browsingContext.userPromptClosed' event.
75
+ *
76
+ * @param {Function} callback - The callback function to handle the event.
77
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
78
+ */
46
79
  async onUserPromptClosed(callback) {
47
80
  await this.subscribeAndHandleEvent('browsingContext.userPromptClosed', callback)
48
81
  }
49
82
 
83
+ /**
84
+ * Subscribes to the 'browsingContext.userPromptOpened' event.
85
+ *
86
+ * @param {Function} callback - The callback function to handle the event.
87
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
88
+ */
50
89
  async onUserPromptOpened(callback) {
51
90
  await this.subscribeAndHandleEvent('browsingContext.userPromptOpened', callback)
52
91
  }
53
92
 
93
+ /**
94
+ * Subscribes to the 'browsingContext.domContentLoaded' event.
95
+ *
96
+ * @param {Function} callback - The callback function to handle the event.
97
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
98
+ */
54
99
  async onDomContentLoaded(callback) {
55
100
  await this.subscribeAndHandleEvent('browsingContext.domContentLoaded', callback)
56
101
  }
57
102
 
103
+ /**
104
+ * Subscribes to the 'browsingContext.load' event.
105
+ *
106
+ * @param {Function} callback - The callback function to handle the event.
107
+ * @returns {Promise<void>} - A promise that resolves when the event is emitted.
108
+ */
58
109
  async onBrowsingContextLoaded(callback) {
59
110
  await this.subscribeAndHandleEvent('browsingContext.load', callback)
60
111
  }
@@ -15,6 +15,10 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
+ /**
19
+ * Represents information about a browsing context.
20
+ * Described in https://w3c.github.io/webdriver-bidi/#type-browsingContext-Info
21
+ */
18
22
  class BrowsingContextInfo {
19
23
  constructor(id, url, children, parentBrowsingContext) {
20
24
  this._id = id
@@ -23,24 +27,51 @@ class BrowsingContextInfo {
23
27
  this._parentBrowsingContext = parentBrowsingContext
24
28
  }
25
29
 
30
+ /**
31
+ * Get the ID of the browsing context.
32
+ * @returns {string} The ID of the browsing context.
33
+ */
26
34
  get id() {
27
35
  return this._id
28
36
  }
29
37
 
38
+ /**
39
+ * Get the URL of the browsing context.
40
+ * @returns {string} The URL of the browsing context.
41
+ */
30
42
  get url() {
31
43
  return this._url
32
44
  }
33
45
 
46
+ /**
47
+ * Get the children of the browsing context.
48
+ * @returns {Array<BrowsingContextInfo>} The children of the browsing context.
49
+ */
34
50
  get children() {
35
51
  return this._children
36
52
  }
37
53
 
54
+ /**
55
+ * Get the parent browsing context.
56
+ * @returns {BrowsingContextInfo} The parent browsing context.
57
+ */
38
58
  get parentBrowsingContext() {
39
59
  return this._parentBrowsingContext
40
60
  }
41
61
  }
42
62
 
63
+ /**
64
+ * Represents information about a navigation.
65
+ * Described in https://w3c.github.io/webdriver-bidi/#type-browsingContext-NavigationInfo.
66
+ */
43
67
  class NavigationInfo {
68
+ /**
69
+ * Constructs a new NavigationInfo object.
70
+ * @param {string} browsingContextId - The ID of the browsing context.
71
+ * @param {string} navigationId - The ID of the navigation.
72
+ * @param {number} timestamp - The timestamp of the navigation.
73
+ * @param {string} url - The URL of the page navigated to.
74
+ */
44
75
  constructor(browsingContextId, navigationId, timestamp, url) {
45
76
  this.browsingContextId = browsingContextId
46
77
  this.navigationId = navigationId