selenium-webdriver 4.16.0 → 4.18.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 (65) hide show
  1. package/CHANGES.md +253 -196
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/bidi/addInterceptParameters.js +86 -0
  5. package/bidi/browsingContext.js +167 -38
  6. package/bidi/browsingContextInspector.js +13 -40
  7. package/bidi/evaluateResult.js +4 -10
  8. package/bidi/filterBy.js +2 -6
  9. package/bidi/index.js +31 -29
  10. package/bidi/input.js +97 -0
  11. package/bidi/interceptPhase.js +24 -0
  12. package/bidi/logInspector.js +15 -20
  13. package/bidi/network.js +178 -0
  14. package/bidi/networkInspector.js +12 -2
  15. package/bidi/networkTypes.js +22 -49
  16. package/bidi/protocolType.js +4 -9
  17. package/bidi/protocolValue.js +48 -17
  18. package/bidi/realmInfo.js +3 -10
  19. package/bidi/scriptManager.js +60 -48
  20. package/bidi/scriptTypes.js +58 -0
  21. package/bidi/urlPattern.js +58 -0
  22. package/bin/linux/selenium-manager +0 -0
  23. package/bin/macos/selenium-manager +0 -0
  24. package/bin/windows/selenium-manager.exe +0 -0
  25. package/chrome.js +2 -14
  26. package/chromium.js +28 -143
  27. package/common/driverFinder.js +1 -1
  28. package/common/seleniumManager.js +5 -12
  29. package/devtools/CDPConnection.js +1 -3
  30. package/edge.js +1 -3
  31. package/example/chrome_android.js +2 -5
  32. package/example/chrome_mobile_emulation.js +2 -4
  33. package/example/google_search.js +1 -3
  34. package/example/headless.js +4 -10
  35. package/example/logging.js +3 -9
  36. package/firefox.js +37 -111
  37. package/http/index.js +7 -10
  38. package/ie.js +5 -15
  39. package/index.js +10 -32
  40. package/io/exec.js +1 -2
  41. package/io/index.js +3 -3
  42. package/io/zip.js +8 -30
  43. package/lib/atoms/find-elements.js +1 -1
  44. package/lib/atoms/get-attribute.js +6 -100
  45. package/lib/by.js +2 -9
  46. package/lib/capabilities.js +8 -7
  47. package/lib/command.js +4 -0
  48. package/lib/error.js +2 -9
  49. package/lib/http.js +37 -130
  50. package/lib/input.js +22 -34
  51. package/lib/logging.js +3 -11
  52. package/lib/promise.js +2 -7
  53. package/lib/select.js +3 -9
  54. package/lib/until.js +28 -49
  55. package/lib/util.js +1 -4
  56. package/lib/virtual_authenticator.js +4 -22
  57. package/lib/webdriver.js +146 -269
  58. package/lib/webelement.js +1 -5
  59. package/net/index.js +1 -4
  60. package/package.json +2 -1
  61. package/remote/index.js +9 -24
  62. package/remote/util.js +6 -19
  63. package/safari.js +3 -8
  64. package/testing/index.js +6 -11
  65. package/example/firefox_channels.js +0 -84
package/lib/webdriver.js CHANGED
@@ -42,6 +42,7 @@ const webElement = require('./webelement')
42
42
  const { isObject } = require('./util')
43
43
  const BIDI = require('../bidi')
44
44
  const { PinnedScript } = require('./pinnedScript')
45
+ const JSZip = require('jszip')
45
46
 
46
47
  // Capability names that are defined in the W3C spec.
47
48
  const W3C_CAPABILITY_NAMES = new Set([
@@ -147,11 +148,7 @@ async function toWireValue(obj) {
147
148
  return value
148
149
  }
149
150
 
150
- if (
151
- typeof value === 'boolean' ||
152
- typeof value === 'number' ||
153
- typeof value === 'string'
154
- ) {
151
+ if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
155
152
  return value
156
153
  }
157
154
 
@@ -235,9 +232,7 @@ function fromWireValue(driver, value) {
235
232
  * @return {string} The resolved message
236
233
  */
237
234
  function resolveWaitMessage(message) {
238
- return message
239
- ? `${typeof message === 'function' ? message() : message}\n`
240
- : ''
235
+ return message ? `${typeof message === 'function' ? message() : message}\n` : ''
241
236
  }
242
237
 
243
238
  /**
@@ -775,8 +770,8 @@ class WebDriver {
775
770
  this.session_ = Promise.reject(
776
771
  new error.NoSuchSessionError(
777
772
  'This driver instance does not have a valid session ID ' +
778
- '(did you call WebDriver.quit()?) and may no longer be used.'
779
- )
773
+ '(did you call WebDriver.quit()?) and may no longer be used.',
774
+ ),
780
775
  )
781
776
 
782
777
  // Only want the session rejection to bubble if accessed.
@@ -803,14 +798,12 @@ class WebDriver {
803
798
  return this.execute(
804
799
  new command.Command(command.Name.EXECUTE_SCRIPT)
805
800
  .setParameter('script', script.executionScript())
806
- .setParameter('args', args)
801
+ .setParameter('args', args),
807
802
  )
808
803
  }
809
804
 
810
805
  return this.execute(
811
- new command.Command(command.Name.EXECUTE_SCRIPT)
812
- .setParameter('script', script)
813
- .setParameter('args', args)
806
+ new command.Command(command.Name.EXECUTE_SCRIPT).setParameter('script', script).setParameter('args', args),
814
807
  )
815
808
  }
816
809
 
@@ -824,14 +817,12 @@ class WebDriver {
824
817
  return this.execute(
825
818
  new command.Command(command.Name.EXECUTE_ASYNC_SCRIPT)
826
819
  .setParameter('script', script.executionScript())
827
- .setParameter('args', args)
820
+ .setParameter('args', args),
828
821
  )
829
822
  }
830
823
 
831
824
  return this.execute(
832
- new command.Command(command.Name.EXECUTE_ASYNC_SCRIPT)
833
- .setParameter('script', script)
834
- .setParameter('args', args)
825
+ new command.Command(command.Name.EXECUTE_ASYNC_SCRIPT).setParameter('script', script).setParameter('args', args),
835
826
  )
836
827
  }
837
828
 
@@ -859,20 +850,14 @@ class WebDriver {
859
850
  let timeoutMessage = resolveWaitMessage(message)
860
851
  reject(
861
852
  new error.TimeoutError(
862
- `${timeoutMessage}Timed out waiting for promise to resolve after ${
863
- Date.now() - start
864
- }ms`
865
- )
853
+ `${timeoutMessage}Timed out waiting for promise to resolve after ${Date.now() - start}ms`,
854
+ ),
866
855
  )
867
856
  } catch (ex) {
868
857
  reject(
869
858
  new error.TimeoutError(
870
- `${
871
- ex.message
872
- }\nTimed out waiting for promise to resolve after ${
873
- Date.now() - start
874
- }ms`
875
- )
859
+ `${ex.message}\nTimed out waiting for promise to resolve after ${Date.now() - start}ms`,
860
+ ),
876
861
  )
877
862
  }
878
863
  }, timeout)
@@ -886,7 +871,7 @@ class WebDriver {
886
871
  function (error) {
887
872
  clearTimer()
888
873
  reject(error)
889
- }
874
+ },
890
875
  )
891
876
  })
892
877
  }
@@ -898,10 +883,7 @@ class WebDriver {
898
883
  }
899
884
 
900
885
  if (typeof fn !== 'function') {
901
- throw TypeError(
902
- 'Wait condition must be a promise-like object, function, or a ' +
903
- 'Condition object'
904
- )
886
+ throw TypeError('Wait condition must be a promise-like object, function, or a ' + 'Condition object')
905
887
  }
906
888
 
907
889
  const driver = this
@@ -925,17 +907,9 @@ class WebDriver {
925
907
  } else if (timeout && elapsed >= timeout) {
926
908
  try {
927
909
  let timeoutMessage = resolveWaitMessage(message)
928
- reject(
929
- new error.TimeoutError(
930
- `${timeoutMessage}Wait timed out after ${elapsed}ms`
931
- )
932
- )
910
+ reject(new error.TimeoutError(`${timeoutMessage}Wait timed out after ${elapsed}ms`))
933
911
  } catch (ex) {
934
- reject(
935
- new error.TimeoutError(
936
- `${ex.message}\nWait timed out after ${elapsed}ms`
937
- )
938
- )
912
+ reject(new error.TimeoutError(`${ex.message}\nWait timed out after ${elapsed}ms`))
939
913
  }
940
914
  } else {
941
915
  setTimeout(pollCondition, pollTimeout)
@@ -951,12 +925,11 @@ class WebDriver {
951
925
  result.then(function (value) {
952
926
  if (!(value instanceof WebElement)) {
953
927
  throw TypeError(
954
- 'WebElementCondition did not resolve to a WebElement: ' +
955
- Object.prototype.toString.call(value)
928
+ 'WebElementCondition did not resolve to a WebElement: ' + Object.prototype.toString.call(value),
956
929
  )
957
930
  }
958
931
  return value
959
- })
932
+ }),
960
933
  )
961
934
  }
962
935
  return result
@@ -969,9 +942,7 @@ class WebDriver {
969
942
 
970
943
  /** @override */
971
944
  getWindowHandle() {
972
- return this.execute(
973
- new command.Command(command.Name.GET_CURRENT_WINDOW_HANDLE)
974
- )
945
+ return this.execute(new command.Command(command.Name.GET_CURRENT_WINDOW_HANDLE))
975
946
  }
976
947
 
977
948
  /** @override */
@@ -1010,9 +981,7 @@ class WebDriver {
1010
981
  let cmd = null
1011
982
 
1012
983
  if (locator instanceof RelativeBy) {
1013
- cmd = new command.Command(
1014
- command.Name.FIND_ELEMENTS_RELATIVE
1015
- ).setParameter('args', locator.marshall())
984
+ cmd = new command.Command(command.Name.FIND_ELEMENTS_RELATIVE).setParameter('args', locator.marshall())
1016
985
  } else {
1017
986
  locator = by.checkedLocator(locator)
1018
987
  }
@@ -1041,9 +1010,7 @@ class WebDriver {
1041
1010
  async normalize_(webElementPromise) {
1042
1011
  let result = await webElementPromise
1043
1012
  if (result.length === 0) {
1044
- throw new NoSuchElementError(
1045
- 'Cannot locate an element with provided parameters'
1046
- )
1013
+ throw new NoSuchElementError('Cannot locate an element with provided parameters')
1047
1014
  } else {
1048
1015
  return result[0]
1049
1016
  }
@@ -1071,9 +1038,7 @@ class WebDriver {
1071
1038
  async findElements(locator) {
1072
1039
  let cmd = null
1073
1040
  if (locator instanceof RelativeBy) {
1074
- cmd = new command.Command(
1075
- command.Name.FIND_ELEMENTS_RELATIVE
1076
- ).setParameter('args', locator.marshall())
1041
+ cmd = new command.Command(command.Name.FIND_ELEMENTS_RELATIVE).setParameter('args', locator.marshall())
1077
1042
  } else {
1078
1043
  locator = by.checkedLocator(locator)
1079
1044
  }
@@ -1215,9 +1180,7 @@ class WebDriver {
1215
1180
  let self = this
1216
1181
  resultObj = self.validatePrintPageParams(keys, params)
1217
1182
 
1218
- return this.execute(
1219
- new command.Command(command.Name.PRINT_PAGE).setParameters(resultObj)
1220
- )
1183
+ return this.execute(new command.Command(command.Name.PRINT_PAGE).setParameters(resultObj))
1221
1184
  }
1222
1185
 
1223
1186
  /**
@@ -1231,9 +1194,7 @@ class WebDriver {
1231
1194
 
1232
1195
  if (process.env.SELENIUM_REMOTE_URL) {
1233
1196
  const host = new URL(process.env.SELENIUM_REMOTE_URL).host
1234
- const sessionId = await this.getSession().then((session) =>
1235
- session.getId()
1236
- )
1197
+ const sessionId = await this.getSession().then((session) => session.getId())
1237
1198
  debuggerUrl = `ws://${host}/session/${sessionId}/se/cdp`
1238
1199
  } else {
1239
1200
  const seCdp = caps['map_'].get('se:cdp')
@@ -1247,9 +1208,7 @@ class WebDriver {
1247
1208
  this._wsUrl = await this.getWsUrl(debuggerUrl, target, caps)
1248
1209
  return new Promise((resolve, reject) => {
1249
1210
  try {
1250
- this._wsConnection = new WebSocket(
1251
- this._wsUrl.replace('localhost', '127.0.0.1')
1252
- )
1211
+ this._wsConnection = new WebSocket(this._wsUrl.replace('localhost', '127.0.0.1'))
1253
1212
  this._cdpConnection = new cdp.CdpConnection(this._wsConnection)
1254
1213
  } catch (err) {
1255
1214
  reject(err)
@@ -1268,11 +1227,7 @@ class WebDriver {
1268
1227
  const page = targets.find((info) => info.type === 'page')
1269
1228
  if (page) {
1270
1229
  this.targetID = page.targetId
1271
- this._cdpConnection.execute(
1272
- 'Target.attachToTarget',
1273
- { targetId: this.targetID, flatten: true },
1274
- null
1275
- )
1230
+ this._cdpConnection.execute('Target.attachToTarget', { targetId: this.targetID, flatten: true }, null)
1276
1231
  } else {
1277
1232
  reject('Unable to find Page target.')
1278
1233
  }
@@ -1324,10 +1279,7 @@ class WebDriver {
1324
1279
  let path
1325
1280
  if (target === 'page' && caps['map_'].get('browserName') !== 'firefox') {
1326
1281
  path = '/json'
1327
- } else if (
1328
- target === 'page' &&
1329
- caps['map_'].get('browserName') === 'firefox'
1330
- ) {
1282
+ } else if (target === 'page' && caps['map_'].get('browserName') === 'firefox') {
1331
1283
  path = '/json/list'
1332
1284
  } else {
1333
1285
  path = '/json/version'
@@ -1379,14 +1331,14 @@ class WebDriver {
1379
1331
  {
1380
1332
  handleAuthRequests: true,
1381
1333
  },
1382
- null
1334
+ null,
1383
1335
  )
1384
1336
  await connection.execute(
1385
1337
  'Network.setCacheDisabled',
1386
1338
  {
1387
1339
  cacheDisabled: true,
1388
1340
  },
1389
- null
1341
+ null,
1390
1342
  )
1391
1343
  }
1392
1344
 
@@ -1424,7 +1376,7 @@ class WebDriver {
1424
1376
  {
1425
1377
  cacheDisabled: true,
1426
1378
  },
1427
- null
1379
+ null,
1428
1380
  )
1429
1381
  }
1430
1382
  /**
@@ -1500,7 +1452,7 @@ class WebDriver {
1500
1452
  {
1501
1453
  name: '__webdriver_attribute',
1502
1454
  },
1503
- null
1455
+ null,
1504
1456
  )
1505
1457
 
1506
1458
  let mutationListener = ''
@@ -1508,18 +1460,10 @@ class WebDriver {
1508
1460
  // Depending on what is running the code it could appear in 2 different places which is why we try
1509
1461
  // here and then the other location
1510
1462
  mutationListener = fs
1511
- .readFileSync(
1512
- './javascript/node/selenium-webdriver/lib/atoms/mutation-listener.js',
1513
- 'utf-8'
1514
- )
1463
+ .readFileSync('./javascript/node/selenium-webdriver/lib/atoms/mutation-listener.js', 'utf-8')
1515
1464
  .toString()
1516
1465
  } catch {
1517
- mutationListener = fs
1518
- .readFileSync(
1519
- path.resolve(__dirname, './atoms/mutation-listener.js'),
1520
- 'utf-8'
1521
- )
1522
- .toString()
1466
+ mutationListener = fs.readFileSync(path.resolve(__dirname, './atoms/mutation-listener.js'), 'utf-8').toString()
1523
1467
  }
1524
1468
 
1525
1469
  this.executeScript(mutationListener)
@@ -1529,7 +1473,7 @@ class WebDriver {
1529
1473
  {
1530
1474
  source: mutationListener,
1531
1475
  },
1532
- null
1476
+ null,
1533
1477
  )
1534
1478
 
1535
1479
  this._wsConnection.on('message', async (message) => {
@@ -1571,15 +1515,12 @@ class WebDriver {
1571
1515
  {
1572
1516
  expression: pinnedScript.creationScript(),
1573
1517
  },
1574
- null
1518
+ null,
1575
1519
  )
1576
1520
 
1577
- let result = await connection.send(
1578
- 'Page.addScriptToEvaluateOnNewDocument',
1579
- {
1580
- source: pinnedScript.creationScript(),
1581
- }
1582
- )
1521
+ let result = await connection.send('Page.addScriptToEvaluateOnNewDocument', {
1522
+ source: pinnedScript.creationScript(),
1523
+ })
1583
1524
 
1584
1525
  pinnedScript.scriptId = result['result']['identifier']
1585
1526
 
@@ -1608,7 +1549,7 @@ class WebDriver {
1608
1549
  {
1609
1550
  expression: script.removalScript(),
1610
1551
  },
1611
- null
1552
+ null,
1612
1553
  )
1613
1554
 
1614
1555
  await connection.execute(
@@ -1616,7 +1557,7 @@ class WebDriver {
1616
1557
  {
1617
1558
  identifier: script.scriptId,
1618
1559
  },
1619
- null
1560
+ null,
1620
1561
  )
1621
1562
 
1622
1563
  delete this.pinnedScripts_[script.handle]
@@ -1637,9 +1578,7 @@ class WebDriver {
1637
1578
  */
1638
1579
  async addVirtualAuthenticator(options) {
1639
1580
  this.authenticatorId_ = await this.execute(
1640
- new command.Command(command.Name.ADD_VIRTUAL_AUTHENTICATOR).setParameters(
1641
- options.toDict()
1642
- )
1581
+ new command.Command(command.Name.ADD_VIRTUAL_AUTHENTICATOR).setParameters(options.toDict()),
1643
1582
  )
1644
1583
  }
1645
1584
 
@@ -1649,9 +1588,10 @@ class WebDriver {
1649
1588
  */
1650
1589
  async removeVirtualAuthenticator() {
1651
1590
  await this.execute(
1652
- new command.Command(
1653
- command.Name.REMOVE_VIRTUAL_AUTHENTICATOR
1654
- ).setParameter('authenticatorId', this.authenticatorId_)
1591
+ new command.Command(command.Name.REMOVE_VIRTUAL_AUTHENTICATOR).setParameter(
1592
+ 'authenticatorId',
1593
+ this.authenticatorId_,
1594
+ ),
1655
1595
  )
1656
1596
  this.authenticatorId_ = null
1657
1597
  }
@@ -1663,9 +1603,7 @@ class WebDriver {
1663
1603
  async addCredential(credential) {
1664
1604
  credential = credential.toDict()
1665
1605
  credential['authenticatorId'] = this.authenticatorId_
1666
- await this.execute(
1667
- new command.Command(command.Name.ADD_CREDENTIAL).setParameters(credential)
1668
- )
1606
+ await this.execute(new command.Command(command.Name.ADD_CREDENTIAL).setParameters(credential))
1669
1607
  }
1670
1608
 
1671
1609
  /**
@@ -1674,10 +1612,7 @@ class WebDriver {
1674
1612
  */
1675
1613
  async getCredentials() {
1676
1614
  let credential_data = await this.execute(
1677
- new command.Command(command.Name.GET_CREDENTIALS).setParameter(
1678
- 'authenticatorId',
1679
- this.virtualAuthenticatorId()
1680
- )
1615
+ new command.Command(command.Name.GET_CREDENTIALS).setParameter('authenticatorId', this.virtualAuthenticatorId()),
1681
1616
  )
1682
1617
  var credential_list = []
1683
1618
  for (var i = 0; i < credential_data.length; i++) {
@@ -1699,7 +1634,7 @@ class WebDriver {
1699
1634
  await this.execute(
1700
1635
  new command.Command(command.Name.REMOVE_CREDENTIAL)
1701
1636
  .setParameter('credentialId', credential_id)
1702
- .setParameter('authenticatorId', this.authenticatorId_)
1637
+ .setParameter('authenticatorId', this.authenticatorId_),
1703
1638
  )
1704
1639
  }
1705
1640
 
@@ -1708,10 +1643,7 @@ class WebDriver {
1708
1643
  */
1709
1644
  async removeAllCredentials() {
1710
1645
  await this.execute(
1711
- new command.Command(command.Name.REMOVE_ALL_CREDENTIALS).setParameter(
1712
- 'authenticatorId',
1713
- this.authenticatorId_
1714
- )
1646
+ new command.Command(command.Name.REMOVE_ALL_CREDENTIALS).setParameter('authenticatorId', this.authenticatorId_),
1715
1647
  )
1716
1648
  }
1717
1649
 
@@ -1723,9 +1655,60 @@ class WebDriver {
1723
1655
  await this.execute(
1724
1656
  new command.Command(command.Name.SET_USER_VERIFIED)
1725
1657
  .setParameter('authenticatorId', this.authenticatorId_)
1726
- .setParameter('isUserVerified', verified)
1658
+ .setParameter('isUserVerified', verified),
1727
1659
  )
1728
1660
  }
1661
+
1662
+ async getDownloadableFiles() {
1663
+ const caps = await this.getCapabilities()
1664
+ if (!caps['map_'].get('se:downloadsEnabled')) {
1665
+ throw new error.WebDriverError('Downloads must be enabled in options')
1666
+ }
1667
+
1668
+ return (await this.execute(new command.Command(command.Name.GET_DOWNLOADABLE_FILES))).names
1669
+ }
1670
+
1671
+ async downloadFile(fileName, targetDirectory) {
1672
+ const caps = await this.getCapabilities()
1673
+ if (!caps['map_'].get('se:downloadsEnabled')) {
1674
+ throw new Error('Downloads must be enabled in options')
1675
+ }
1676
+
1677
+ const response = await this.execute(new command.Command(command.Name.DOWNLOAD_FILE).setParameter('name', fileName))
1678
+
1679
+ const base64Content = response.contents
1680
+
1681
+ if (!targetDirectory.endsWith('/')) {
1682
+ targetDirectory += '/'
1683
+ }
1684
+
1685
+ fs.mkdirSync(targetDirectory, { recursive: true })
1686
+ const zipFilePath = path.join(targetDirectory, `${fileName}.zip`)
1687
+ fs.writeFileSync(zipFilePath, Buffer.from(base64Content, 'base64'))
1688
+
1689
+ const zipData = fs.readFileSync(zipFilePath)
1690
+ await JSZip.loadAsync(zipData)
1691
+ .then((zip) => {
1692
+ // Iterate through each file in the zip archive
1693
+ Object.keys(zip.files).forEach(async (fileName) => {
1694
+ const fileData = await zip.files[fileName].async('nodebuffer')
1695
+ fs.writeFileSync(`${targetDirectory}/${fileName}`, fileData)
1696
+ console.log(`File extracted: ${fileName}`)
1697
+ })
1698
+ })
1699
+ .catch((error) => {
1700
+ console.error('Error unzipping file:', error)
1701
+ })
1702
+ }
1703
+
1704
+ async deleteDownloadableFiles() {
1705
+ const caps = await this.getCapabilities()
1706
+ if (!caps['map_'].get('se:downloadsEnabled')) {
1707
+ throw new error.WebDriverError('Downloads must be enabled in options')
1708
+ }
1709
+
1710
+ return await this.execute(new command.Command(command.Name.DELETE_DOWNLOADABLE_FILES))
1711
+ }
1729
1712
  }
1730
1713
 
1731
1714
  /**
@@ -1756,9 +1739,7 @@ class Navigation {
1756
1739
  * has been loaded.
1757
1740
  */
1758
1741
  to(url) {
1759
- return this.driver_.execute(
1760
- new command.Command(command.Name.GET).setParameter('url', url)
1761
- )
1742
+ return this.driver_.execute(new command.Command(command.Name.GET).setParameter('url', url))
1762
1743
  }
1763
1744
 
1764
1745
  /**
@@ -1842,9 +1823,7 @@ class Options {
1842
1823
 
1843
1824
  // We do not allow ';' in value.
1844
1825
  if (/;/.test(value)) {
1845
- throw new error.InvalidArgumentError(
1846
- 'Invalid cookie value "' + value + '"'
1847
- )
1826
+ throw new error.InvalidArgumentError('Invalid cookie value "' + value + '"')
1848
1827
  }
1849
1828
 
1850
1829
  if (typeof expiry === 'number') {
@@ -1856,14 +1835,12 @@ class Options {
1856
1835
 
1857
1836
  if (sameSite && !['Strict', 'Lax', 'None'].includes(sameSite)) {
1858
1837
  throw new error.InvalidArgumentError(
1859
- `Invalid sameSite cookie value '${sameSite}'. It should be one of "Lax", "Strict" or "None"`
1838
+ `Invalid sameSite cookie value '${sameSite}'. It should be one of "Lax", "Strict" or "None"`,
1860
1839
  )
1861
1840
  }
1862
1841
 
1863
1842
  if (sameSite === 'None' && !secure) {
1864
- throw new error.InvalidArgumentError(
1865
- 'Invalid cookie configuration: SameSite=None must be Secure'
1866
- )
1843
+ throw new error.InvalidArgumentError('Invalid cookie configuration: SameSite=None must be Secure')
1867
1844
  }
1868
1845
 
1869
1846
  return this.driver_.execute(
@@ -1876,7 +1853,7 @@ class Options {
1876
1853
  httpOnly: !!httpOnly,
1877
1854
  expiry: expiry,
1878
1855
  sameSite: sameSite,
1879
- })
1856
+ }),
1880
1857
  )
1881
1858
  }
1882
1859
 
@@ -1887,9 +1864,7 @@ class Options {
1887
1864
  * when all cookies have been deleted.
1888
1865
  */
1889
1866
  deleteAllCookies() {
1890
- return this.driver_.execute(
1891
- new command.Command(command.Name.DELETE_ALL_COOKIES)
1892
- )
1867
+ return this.driver_.execute(new command.Command(command.Name.DELETE_ALL_COOKIES))
1893
1868
  }
1894
1869
 
1895
1870
  /**
@@ -1901,9 +1876,7 @@ class Options {
1901
1876
  * when the cookie has been deleted.
1902
1877
  */
1903
1878
  deleteCookie(name) {
1904
- return this.driver_.execute(
1905
- new command.Command(command.Name.DELETE_COOKIE).setParameter('name', name)
1906
- )
1879
+ return this.driver_.execute(new command.Command(command.Name.DELETE_COOKIE).setParameter('name', name))
1907
1880
  }
1908
1881
 
1909
1882
  /**
@@ -1914,9 +1887,7 @@ class Options {
1914
1887
  * resolved with the cookies visible to the current browsing context.
1915
1888
  */
1916
1889
  getCookies() {
1917
- return this.driver_.execute(
1918
- new command.Command(command.Name.GET_ALL_COOKIES)
1919
- )
1890
+ return this.driver_.execute(new command.Command(command.Name.GET_ALL_COOKIES))
1920
1891
  }
1921
1892
 
1922
1893
  /**
@@ -1931,15 +1902,10 @@ class Options {
1931
1902
  */
1932
1903
  async getCookie(name) {
1933
1904
  try {
1934
- const cookie = await this.driver_.execute(
1935
- new command.Command(command.Name.GET_COOKIE).setParameter('name', name)
1936
- )
1905
+ const cookie = await this.driver_.execute(new command.Command(command.Name.GET_COOKIE).setParameter('name', name))
1937
1906
  return cookie
1938
1907
  } catch (err) {
1939
- if (
1940
- !(err instanceof error.UnknownCommandError) &&
1941
- !(err instanceof error.UnsupportedOperationError)
1942
- ) {
1908
+ if (!(err instanceof error.UnknownCommandError) && !(err instanceof error.UnsupportedOperationError)) {
1943
1909
  throw err
1944
1910
  }
1945
1911
 
@@ -2005,10 +1971,7 @@ class Options {
2005
1971
  valid = true
2006
1972
  cmd.setParameter(key, value)
2007
1973
  } else if (typeof value !== 'undefined') {
2008
- throw TypeError(
2009
- 'invalid timeouts configuration:' +
2010
- ` expected "${key}" to be a number, got ${typeof value}`
2011
- )
1974
+ throw TypeError('invalid timeouts configuration:' + ` expected "${key}" to be a number, got ${typeof value}`)
2012
1975
  }
2013
1976
  }
2014
1977
  setParam('implicit', implicit)
@@ -2056,11 +2019,7 @@ class Options {
2056
2019
  * @return {!Promise<void>}
2057
2020
  */
2058
2021
  function legacyTimeout(driver, type, ms) {
2059
- return driver.execute(
2060
- new command.Command(command.Name.SET_TIMEOUT)
2061
- .setParameter('type', type)
2062
- .setParameter('ms', ms)
2063
- )
2022
+ return driver.execute(new command.Command(command.Name.SET_TIMEOUT).setParameter('type', type).setParameter('ms', ms))
2064
2023
  }
2065
2024
 
2066
2025
  /**
@@ -2170,9 +2129,7 @@ class Window {
2170
2129
  * A promise that will resolve to the window rect of the current window.
2171
2130
  */
2172
2131
  getRect() {
2173
- return this.driver_.execute(
2174
- new command.Command(command.Name.GET_WINDOW_RECT)
2175
- )
2132
+ return this.driver_.execute(new command.Command(command.Name.GET_WINDOW_RECT))
2176
2133
  }
2177
2134
 
2178
2135
  /**
@@ -2196,7 +2153,7 @@ class Window {
2196
2153
  y,
2197
2154
  width,
2198
2155
  height,
2199
- })
2156
+ }),
2200
2157
  )
2201
2158
  }
2202
2159
 
@@ -2210,10 +2167,7 @@ class Window {
2210
2167
  */
2211
2168
  maximize() {
2212
2169
  return this.driver_.execute(
2213
- new command.Command(command.Name.MAXIMIZE_WINDOW).setParameter(
2214
- 'windowHandle',
2215
- 'current'
2216
- )
2170
+ new command.Command(command.Name.MAXIMIZE_WINDOW).setParameter('windowHandle', 'current'),
2217
2171
  )
2218
2172
  }
2219
2173
 
@@ -2226,9 +2180,7 @@ class Window {
2226
2180
  * has completed.
2227
2181
  */
2228
2182
  minimize() {
2229
- return this.driver_.execute(
2230
- new command.Command(command.Name.MINIMIZE_WINDOW)
2231
- )
2183
+ return this.driver_.execute(new command.Command(command.Name.MINIMIZE_WINDOW))
2232
2184
  }
2233
2185
 
2234
2186
  /**
@@ -2242,9 +2194,7 @@ class Window {
2242
2194
  * @see <https://fullscreen.spec.whatwg.org/#fullscreen-an-element>
2243
2195
  */
2244
2196
  fullscreen() {
2245
- return this.driver_.execute(
2246
- new command.Command(command.Name.FULLSCREEN_WINDOW)
2247
- )
2197
+ return this.driver_.execute(new command.Command(command.Name.FULLSCREEN_WINDOW))
2248
2198
  }
2249
2199
 
2250
2200
  /**
@@ -2254,9 +2204,7 @@ class Window {
2254
2204
  */
2255
2205
  async getSize(windowHandle = 'current') {
2256
2206
  if (windowHandle !== 'current') {
2257
- this.log_.warning(
2258
- `Only 'current' window is supported for W3C compatible browsers.`
2259
- )
2207
+ this.log_.warning(`Only 'current' window is supported for W3C compatible browsers.`)
2260
2208
  }
2261
2209
 
2262
2210
  const rect = await this.getRect()
@@ -2272,14 +2220,9 @@ class Window {
2272
2220
  * @param windowHandle
2273
2221
  * @returns {Promise<void>}
2274
2222
  */
2275
- async setSize(
2276
- { x = 0, y = 0, width = 0, height = 0 },
2277
- windowHandle = 'current'
2278
- ) {
2223
+ async setSize({ x = 0, y = 0, width = 0, height = 0 }, windowHandle = 'current') {
2279
2224
  if (windowHandle !== 'current') {
2280
- this.log_.warning(
2281
- `Only 'current' window is supported for W3C compatible browsers.`
2282
- )
2225
+ this.log_.warning(`Only 'current' window is supported for W3C compatible browsers.`)
2283
2226
  }
2284
2227
 
2285
2228
  await this.setRect({ x, y, width, height })
@@ -2321,19 +2264,11 @@ class Logs {
2321
2264
  * type.
2322
2265
  */
2323
2266
  get(type) {
2324
- let cmd = new command.Command(command.Name.GET_LOG).setParameter(
2325
- 'type',
2326
- type
2327
- )
2267
+ let cmd = new command.Command(command.Name.GET_LOG).setParameter('type', type)
2328
2268
  return this.driver_.execute(cmd).then(function (entries) {
2329
2269
  return entries.map(function (entry) {
2330
2270
  if (!(entry instanceof logging.Entry)) {
2331
- return new logging.Entry(
2332
- entry['level'],
2333
- entry['message'],
2334
- entry['timestamp'],
2335
- entry['type']
2336
- )
2271
+ return new logging.Entry(entry['level'], entry['message'], entry['timestamp'], entry['type'])
2337
2272
  }
2338
2273
  return entry
2339
2274
  })
@@ -2346,9 +2281,7 @@ class Logs {
2346
2281
  * promise that will resolve to a list of available log types.
2347
2282
  */
2348
2283
  getAvailableLogTypes() {
2349
- return this.driver_.execute(
2350
- new command.Command(command.Name.GET_AVAILABLE_LOG_TYPES)
2351
- )
2284
+ return this.driver_.execute(new command.Command(command.Name.GET_AVAILABLE_LOG_TYPES))
2352
2285
  }
2353
2286
  }
2354
2287
 
@@ -2380,9 +2313,7 @@ class TargetLocator {
2380
2313
  * @return {!WebElementPromise} The active element.
2381
2314
  */
2382
2315
  activeElement() {
2383
- const id = this.driver_.execute(
2384
- new command.Command(command.Name.GET_ACTIVE_ELEMENT)
2385
- )
2316
+ const id = this.driver_.execute(new command.Command(command.Name.GET_ACTIVE_ELEMENT))
2386
2317
  return new WebElementPromise(this.driver_, id)
2387
2318
  }
2388
2319
 
@@ -2394,9 +2325,7 @@ class TargetLocator {
2394
2325
  * when the driver has changed focus to the default content.
2395
2326
  */
2396
2327
  defaultContent() {
2397
- return this.driver_.execute(
2398
- new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', null)
2399
- )
2328
+ return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', null))
2400
2329
  }
2401
2330
 
2402
2331
  /**
@@ -2420,17 +2349,10 @@ class TargetLocator {
2420
2349
  frame(id) {
2421
2350
  let frameReference = id
2422
2351
  if (typeof id === 'string') {
2423
- frameReference = this.driver_
2424
- .findElement({ id })
2425
- .catch((_) => this.driver_.findElement({ name: id }))
2352
+ frameReference = this.driver_.findElement({ id }).catch((_) => this.driver_.findElement({ name: id }))
2426
2353
  }
2427
2354
 
2428
- return this.driver_.execute(
2429
- new command.Command(command.Name.SWITCH_TO_FRAME).setParameter(
2430
- 'id',
2431
- frameReference
2432
- )
2433
- )
2355
+ return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', frameReference))
2434
2356
  }
2435
2357
 
2436
2358
  /**
@@ -2442,9 +2364,7 @@ class TargetLocator {
2442
2364
  * has completed.
2443
2365
  */
2444
2366
  parentFrame() {
2445
- return this.driver_.execute(
2446
- new command.Command(command.Name.SWITCH_TO_FRAME_PARENT)
2447
- )
2367
+ return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME_PARENT))
2448
2368
  }
2449
2369
 
2450
2370
  /**
@@ -2466,7 +2386,7 @@ class TargetLocator {
2466
2386
  // "name" supports the legacy drivers. "handle" is the W3C
2467
2387
  // compliant parameter.
2468
2388
  .setParameter('name', nameOrHandle)
2469
- .setParameter('handle', nameOrHandle)
2389
+ .setParameter('handle', nameOrHandle),
2470
2390
  )
2471
2391
  }
2472
2392
 
@@ -2484,12 +2404,7 @@ class TargetLocator {
2484
2404
  newWindow(typeHint) {
2485
2405
  const driver = this.driver_
2486
2406
  return this.driver_
2487
- .execute(
2488
- new command.Command(command.Name.SWITCH_TO_NEW_WINDOW).setParameter(
2489
- 'type',
2490
- typeHint
2491
- )
2492
- )
2407
+ .execute(new command.Command(command.Name.SWITCH_TO_NEW_WINDOW).setParameter('type', typeHint))
2493
2408
  .then(function (response) {
2494
2409
  return driver.switchTo().window(response.handle)
2495
2410
  })
@@ -2504,15 +2419,13 @@ class TargetLocator {
2504
2419
  * @return {!AlertPromise} The open alert.
2505
2420
  */
2506
2421
  alert() {
2507
- const text = this.driver_.execute(
2508
- new command.Command(command.Name.GET_ALERT_TEXT)
2509
- )
2422
+ const text = this.driver_.execute(new command.Command(command.Name.GET_ALERT_TEXT))
2510
2423
  const driver = this.driver_
2511
2424
  return new AlertPromise(
2512
2425
  driver,
2513
2426
  text.then(function (text) {
2514
2427
  return new Alert(driver, text)
2515
- })
2428
+ }),
2516
2429
  )
2517
2430
  }
2518
2431
  }
@@ -2560,9 +2473,7 @@ class WebElement {
2560
2473
  * @return {!Object} The element ID for use with WebDriver's wire protocol.
2561
2474
  */
2562
2475
  static buildId(id, noLegacy = false) {
2563
- return noLegacy
2564
- ? { [ELEMENT_ID_KEY]: id }
2565
- : { [ELEMENT_ID_KEY]: id, [LEGACY_ELEMENT_ID_KEY]: id }
2476
+ return noLegacy ? { [ELEMENT_ID_KEY]: id } : { [ELEMENT_ID_KEY]: id, [LEGACY_ELEMENT_ID_KEY]: id }
2566
2477
  }
2567
2478
 
2568
2479
  /**
@@ -2789,26 +2700,20 @@ class WebElement {
2789
2700
  return this.execute_(
2790
2701
  new command.Command(command.Name.SEND_KEYS_TO_ELEMENT)
2791
2702
  .setParameter('text', keys.join(''))
2792
- .setParameter('value', keys)
2703
+ .setParameter('value', keys),
2793
2704
  )
2794
2705
  }
2795
2706
 
2796
2707
  try {
2797
- keys = await this.driver_.fileDetector_.handleFile(
2798
- this.driver_,
2799
- keys.join('')
2800
- )
2708
+ keys = await this.driver_.fileDetector_.handleFile(this.driver_, keys.join(''))
2801
2709
  } catch (ex) {
2802
- this.log_.severe(
2803
- 'Error trying parse string as a file with file detector; sending keys instead' +
2804
- ex
2805
- )
2710
+ this.log_.severe('Error trying parse string as a file with file detector; sending keys instead' + ex)
2806
2711
  }
2807
2712
 
2808
2713
  return this.execute_(
2809
2714
  new command.Command(command.Name.SEND_KEYS_TO_ELEMENT)
2810
2715
  .setParameter('text', keys)
2811
- .setParameter('value', keys.split(''))
2716
+ .setParameter('value', keys.split('')),
2812
2717
  )
2813
2718
  }
2814
2719
 
@@ -2838,9 +2743,7 @@ class WebElement {
2838
2743
  */
2839
2744
  getCssValue(cssStyleProperty) {
2840
2745
  const name = command.Name.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
2841
- return this.execute_(
2842
- new command.Command(name).setParameter('propertyName', cssStyleProperty)
2843
- )
2746
+ return this.execute_(new command.Command(name).setParameter('propertyName', cssStyleProperty))
2844
2747
  }
2845
2748
 
2846
2749
  /**
@@ -2873,12 +2776,7 @@ class WebElement {
2873
2776
  * either a string or null.
2874
2777
  */
2875
2778
  getAttribute(attributeName) {
2876
- return this.execute_(
2877
- new command.Command(command.Name.GET_ELEMENT_ATTRIBUTE).setParameter(
2878
- 'name',
2879
- attributeName
2880
- )
2881
- )
2779
+ return this.execute_(new command.Command(command.Name.GET_ELEMENT_ATTRIBUTE).setParameter('name', attributeName))
2882
2780
  }
2883
2781
 
2884
2782
  /**
@@ -2903,12 +2801,7 @@ class WebElement {
2903
2801
  */
2904
2802
 
2905
2803
  getDomAttribute(attributeName) {
2906
- return this.execute_(
2907
- new command.Command(command.Name.GET_DOM_ATTRIBUTE).setParameter(
2908
- 'name',
2909
- attributeName
2910
- )
2911
- )
2804
+ return this.execute_(new command.Command(command.Name.GET_DOM_ATTRIBUTE).setParameter('name', attributeName))
2912
2805
  }
2913
2806
 
2914
2807
  /**
@@ -2918,12 +2811,7 @@ class WebElement {
2918
2811
  * resolved with the element's property value
2919
2812
  */
2920
2813
  getProperty(propertyName) {
2921
- return this.execute_(
2922
- new command.Command(command.Name.GET_ELEMENT_PROPERTY).setParameter(
2923
- 'name',
2924
- propertyName
2925
- )
2926
- )
2814
+ return this.execute_(new command.Command(command.Name.GET_ELEMENT_PROPERTY).setParameter('name', propertyName))
2927
2815
  }
2928
2816
 
2929
2817
  /**
@@ -3051,9 +2939,7 @@ class WebElement {
3051
2939
  * resolved to the screenshot as a base-64 encoded PNG.
3052
2940
  */
3053
2941
  takeScreenshot() {
3054
- return this.execute_(
3055
- new command.Command(command.Name.TAKE_ELEMENT_SCREENSHOT)
3056
- )
2942
+ return this.execute_(new command.Command(command.Name.TAKE_ELEMENT_SCREENSHOT))
3057
2943
  }
3058
2944
  }
3059
2945
 
@@ -3138,11 +3024,7 @@ class ShadowRoot {
3138
3024
  * @return {boolean} whether the object is a valid encoded WebElement ID.
3139
3025
  */
3140
3026
  static isId(obj) {
3141
- return (
3142
- obj &&
3143
- typeof obj === 'object' &&
3144
- typeof obj[SHADOW_ROOT_ID_KEY] === 'string'
3145
- )
3027
+ return obj && typeof obj === 'object' && typeof obj[SHADOW_ROOT_ID_KEY] === 'string'
3146
3028
  }
3147
3029
 
3148
3030
  /**
@@ -3348,12 +3230,7 @@ class Alert {
3348
3230
  * when this command has completed.
3349
3231
  */
3350
3232
  sendKeys(text) {
3351
- return this.driver_.execute(
3352
- new command.Command(command.Name.SET_ALERT_TEXT).setParameter(
3353
- 'text',
3354
- text
3355
- )
3356
- )
3233
+ return this.driver_.execute(new command.Command(command.Name.SET_ALERT_TEXT).setParameter('text', text))
3357
3234
  }
3358
3235
  }
3359
3236