@selenium/atoms 4.51.0-nightly202609302012 → 4.52.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 (331) hide show
  1. package/dist/index.d.ts +40 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +40 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/typescript/active-element.d.ts +2 -0
  6. package/dist/typescript/active-element.d.ts.map +1 -0
  7. package/dist/typescript/active-element.js +19 -0
  8. package/dist/typescript/active-element.js.map +1 -0
  9. package/dist/typescript/clear-local-storage.d.ts +3 -0
  10. package/dist/typescript/clear-local-storage.d.ts.map +1 -0
  11. package/dist/typescript/clear-local-storage.js +25 -0
  12. package/dist/typescript/clear-local-storage.js.map +1 -0
  13. package/dist/typescript/clear-session-storage.d.ts +3 -0
  14. package/dist/typescript/clear-session-storage.d.ts.map +1 -0
  15. package/dist/typescript/clear-session-storage.js +25 -0
  16. package/dist/typescript/clear-session-storage.js.map +1 -0
  17. package/dist/typescript/clear.d.ts +3 -0
  18. package/dist/typescript/clear.d.ts.map +1 -0
  19. package/dist/typescript/clear.js +67 -0
  20. package/dist/typescript/clear.js.map +1 -0
  21. package/dist/typescript/click.d.ts +4 -0
  22. package/dist/typescript/click.d.ts.map +1 -0
  23. package/dist/typescript/click.js +52 -0
  24. package/dist/typescript/click.js.map +1 -0
  25. package/dist/typescript/core/attribute.d.ts +3 -0
  26. package/dist/typescript/core/attribute.d.ts.map +1 -0
  27. package/dist/typescript/core/attribute.js +60 -0
  28. package/dist/typescript/core/attribute.js.map +1 -0
  29. package/dist/typescript/core/color.d.ts +2 -0
  30. package/dist/typescript/core/color.d.ts.map +1 -0
  31. package/dist/typescript/core/color.js +248 -0
  32. package/dist/typescript/core/color.js.map +1 -0
  33. package/dist/typescript/core/editable.d.ts +5 -0
  34. package/dist/typescript/core/editable.d.ts.map +1 -0
  35. package/dist/typescript/core/editable.js +55 -0
  36. package/dist/typescript/core/editable.js.map +1 -0
  37. package/dist/typescript/core/element.d.ts +6 -0
  38. package/dist/typescript/core/element.d.ts.map +1 -0
  39. package/dist/typescript/core/element.js +97 -0
  40. package/dist/typescript/core/element.js.map +1 -0
  41. package/dist/typescript/core/enabled.d.ts +2 -0
  42. package/dist/typescript/core/enabled.d.ts.map +1 -0
  43. package/dist/typescript/core/enabled.js +69 -0
  44. package/dist/typescript/core/enabled.js.map +1 -0
  45. package/dist/typescript/core/error.d.ts +13 -0
  46. package/dist/typescript/core/error.d.ts.map +1 -0
  47. package/dist/typescript/core/error.js +40 -0
  48. package/dist/typescript/core/error.js.map +1 -0
  49. package/dist/typescript/core/events.d.ts +91 -0
  50. package/dist/typescript/core/events.d.ts.map +1 -0
  51. package/dist/typescript/core/events.js +131 -0
  52. package/dist/typescript/core/events.js.map +1 -0
  53. package/dist/typescript/core/focus.d.ts +4 -0
  54. package/dist/typescript/core/focus.d.ts.map +1 -0
  55. package/dist/typescript/core/focus.js +88 -0
  56. package/dist/typescript/core/focus.js.map +1 -0
  57. package/dist/typescript/core/focusable.d.ts +2 -0
  58. package/dist/typescript/core/focusable.d.ts.map +1 -0
  59. package/dist/typescript/core/focusable.js +36 -0
  60. package/dist/typescript/core/focusable.js.map +1 -0
  61. package/dist/typescript/core/form.d.ts +2 -0
  62. package/dist/typescript/core/form.d.ts.map +1 -0
  63. package/dist/typescript/core/form.js +76 -0
  64. package/dist/typescript/core/form.js.map +1 -0
  65. package/dist/typescript/core/frame.d.ts +8 -0
  66. package/dist/typescript/core/frame.d.ts.map +1 -0
  67. package/dist/typescript/core/frame.js +95 -0
  68. package/dist/typescript/core/frame.js.map +1 -0
  69. package/dist/typescript/core/geometry.d.ts +28 -0
  70. package/dist/typescript/core/geometry.d.ts.map +1 -0
  71. package/dist/typescript/core/geometry.js +134 -0
  72. package/dist/typescript/core/geometry.js.map +1 -0
  73. package/dist/typescript/core/inject.d.ts +21 -0
  74. package/dist/typescript/core/inject.d.ts.map +1 -0
  75. package/dist/typescript/core/inject.js +282 -0
  76. package/dist/typescript/core/inject.js.map +1 -0
  77. package/dist/typescript/core/interactable.d.ts +2 -0
  78. package/dist/typescript/core/interactable.d.ts.map +1 -0
  79. package/dist/typescript/core/interactable.js +27 -0
  80. package/dist/typescript/core/interactable.js.map +1 -0
  81. package/dist/typescript/core/keyboard.d.ts +15 -0
  82. package/dist/typescript/core/keyboard.d.ts.map +1 -0
  83. package/dist/typescript/core/keyboard.js +356 -0
  84. package/dist/typescript/core/keyboard.js.map +1 -0
  85. package/dist/typescript/core/keys.d.ts +65 -0
  86. package/dist/typescript/core/keys.d.ts.map +1 -0
  87. package/dist/typescript/core/keys.js +125 -0
  88. package/dist/typescript/core/keys.js.map +1 -0
  89. package/dist/typescript/core/locators.d.ts +6 -0
  90. package/dist/typescript/core/locators.d.ts.map +1 -0
  91. package/dist/typescript/core/locators.js +610 -0
  92. package/dist/typescript/core/locators.js.map +1 -0
  93. package/dist/typescript/core/mouse.d.ts +17 -0
  94. package/dist/typescript/core/mouse.d.ts.map +1 -0
  95. package/dist/typescript/core/mouse.js +186 -0
  96. package/dist/typescript/core/mouse.js.map +1 -0
  97. package/dist/typescript/core/overflow.d.ts +5 -0
  98. package/dist/typescript/core/overflow.d.ts.map +1 -0
  99. package/dist/typescript/core/overflow.js +133 -0
  100. package/dist/typescript/core/overflow.js.map +1 -0
  101. package/dist/typescript/core/scroll.d.ts +3 -0
  102. package/dist/typescript/core/scroll.d.ts.map +1 -0
  103. package/dist/typescript/core/scroll.js +77 -0
  104. package/dist/typescript/core/scroll.js.map +1 -0
  105. package/dist/typescript/core/shown.d.ts +3 -0
  106. package/dist/typescript/core/shown.d.ts.map +1 -0
  107. package/dist/typescript/core/shown.js +190 -0
  108. package/dist/typescript/core/shown.js.map +1 -0
  109. package/dist/typescript/core/storage.d.ts +14 -0
  110. package/dist/typescript/core/storage.d.ts.map +1 -0
  111. package/dist/typescript/core/storage.js +98 -0
  112. package/dist/typescript/core/storage.js.map +1 -0
  113. package/dist/typescript/core/style.d.ts +2 -0
  114. package/dist/typescript/core/style.d.ts.map +1 -0
  115. package/dist/typescript/core/style.js +32 -0
  116. package/dist/typescript/core/style.js.map +1 -0
  117. package/dist/typescript/core/useragent.d.ts +3 -0
  118. package/dist/typescript/core/useragent.d.ts.map +1 -0
  119. package/dist/typescript/core/useragent.js +31 -0
  120. package/dist/typescript/core/useragent.js.map +1 -0
  121. package/dist/typescript/default-content.d.ts +2 -0
  122. package/dist/typescript/default-content.d.ts.map +1 -0
  123. package/dist/typescript/default-content.js +20 -0
  124. package/dist/typescript/default-content.js.map +1 -0
  125. package/dist/typescript/execute-async-script.d.ts +2 -0
  126. package/dist/typescript/execute-async-script.d.ts.map +1 -0
  127. package/dist/typescript/execute-async-script.js +20 -0
  128. package/dist/typescript/execute-async-script.js.map +1 -0
  129. package/dist/typescript/execute-script.d.ts +2 -0
  130. package/dist/typescript/execute-script.d.ts.map +1 -0
  131. package/dist/typescript/execute-script.js +20 -0
  132. package/dist/typescript/execute-script.js.map +1 -0
  133. package/dist/typescript/find-element-fragment.d.ts +8 -0
  134. package/dist/typescript/find-element-fragment.d.ts.map +1 -0
  135. package/dist/typescript/find-element-fragment.js +39 -0
  136. package/dist/typescript/find-element-fragment.js.map +1 -0
  137. package/dist/typescript/find-element.d.ts +2 -0
  138. package/dist/typescript/find-element.d.ts.map +1 -0
  139. package/dist/typescript/find-element.js +18 -0
  140. package/dist/typescript/find-element.js.map +1 -0
  141. package/dist/typescript/find-elements.d.ts +1 -2
  142. package/dist/typescript/find-elements.d.ts.map +1 -1
  143. package/dist/typescript/find-elements.js +1 -289
  144. package/dist/typescript/find-elements.js.map +1 -1
  145. package/dist/typescript/frame-by-id-or-name.d.ts +2 -0
  146. package/dist/typescript/frame-by-id-or-name.d.ts.map +1 -0
  147. package/dist/typescript/frame-by-id-or-name.js +22 -0
  148. package/dist/typescript/frame-by-id-or-name.js.map +1 -0
  149. package/dist/typescript/frame-by-index.d.ts +2 -0
  150. package/dist/typescript/frame-by-index.d.ts.map +1 -0
  151. package/dist/typescript/frame-by-index.js +19 -0
  152. package/dist/typescript/frame-by-index.js.map +1 -0
  153. package/dist/typescript/get-attribute-value.d.ts +2 -0
  154. package/dist/typescript/get-attribute-value.d.ts.map +1 -0
  155. package/dist/typescript/get-attribute-value.js +22 -0
  156. package/dist/typescript/get-attribute-value.js.map +1 -0
  157. package/dist/typescript/get-effective-style.d.ts +3 -0
  158. package/dist/typescript/get-effective-style.d.ts.map +1 -0
  159. package/dist/typescript/get-effective-style.js +84 -0
  160. package/dist/typescript/get-effective-style.js.map +1 -0
  161. package/dist/typescript/get-element-from-cache.d.ts +2 -0
  162. package/dist/typescript/get-element-from-cache.d.ts.map +1 -0
  163. package/dist/typescript/get-element-from-cache.js +20 -0
  164. package/dist/typescript/get-element-from-cache.js.map +1 -0
  165. package/dist/typescript/get-frame-window.d.ts +2 -0
  166. package/dist/typescript/get-frame-window.d.ts.map +1 -0
  167. package/dist/typescript/get-frame-window.js +22 -0
  168. package/dist/typescript/get-frame-window.js.map +1 -0
  169. package/dist/typescript/get-local-storage-item.d.ts +3 -0
  170. package/dist/typescript/get-local-storage-item.d.ts.map +1 -0
  171. package/dist/typescript/get-local-storage-item.js +25 -0
  172. package/dist/typescript/get-local-storage-item.js.map +1 -0
  173. package/dist/typescript/get-local-storage-key.d.ts +3 -0
  174. package/dist/typescript/get-local-storage-key.d.ts.map +1 -0
  175. package/dist/typescript/get-local-storage-key.js +26 -0
  176. package/dist/typescript/get-local-storage-key.js.map +1 -0
  177. package/dist/typescript/get-local-storage-keys.d.ts +3 -0
  178. package/dist/typescript/get-local-storage-keys.d.ts.map +1 -0
  179. package/dist/typescript/get-local-storage-keys.js +25 -0
  180. package/dist/typescript/get-local-storage-keys.js.map +1 -0
  181. package/dist/typescript/get-local-storage-size.d.ts +3 -0
  182. package/dist/typescript/get-local-storage-size.d.ts.map +1 -0
  183. package/dist/typescript/get-local-storage-size.js +25 -0
  184. package/dist/typescript/get-local-storage-size.js.map +1 -0
  185. package/dist/typescript/get-location.d.ts +9 -0
  186. package/dist/typescript/get-location.d.ts.map +1 -0
  187. package/dist/typescript/get-location.js +49 -0
  188. package/dist/typescript/get-location.js.map +1 -0
  189. package/dist/typescript/get-session-storage-item.d.ts +3 -0
  190. package/dist/typescript/get-session-storage-item.d.ts.map +1 -0
  191. package/dist/typescript/get-session-storage-item.js +25 -0
  192. package/dist/typescript/get-session-storage-item.js.map +1 -0
  193. package/dist/typescript/get-session-storage-key.d.ts +3 -0
  194. package/dist/typescript/get-session-storage-key.d.ts.map +1 -0
  195. package/dist/typescript/get-session-storage-key.js +26 -0
  196. package/dist/typescript/get-session-storage-key.js.map +1 -0
  197. package/dist/typescript/get-session-storage-keys.d.ts +3 -0
  198. package/dist/typescript/get-session-storage-keys.d.ts.map +1 -0
  199. package/dist/typescript/get-session-storage-keys.js +25 -0
  200. package/dist/typescript/get-session-storage-keys.js.map +1 -0
  201. package/dist/typescript/get-session-storage-size.d.ts +3 -0
  202. package/dist/typescript/get-session-storage-size.d.ts.map +1 -0
  203. package/dist/typescript/get-session-storage-size.js +25 -0
  204. package/dist/typescript/get-session-storage-size.js.map +1 -0
  205. package/dist/typescript/get-size.d.ts +7 -0
  206. package/dist/typescript/get-size.d.ts.map +1 -0
  207. package/dist/typescript/get-size.js +36 -0
  208. package/dist/typescript/get-size.js.map +1 -0
  209. package/dist/typescript/get-text.d.ts +3 -0
  210. package/dist/typescript/get-text.d.ts.map +1 -0
  211. package/dist/typescript/get-text.js +294 -0
  212. package/dist/typescript/get-text.js.map +1 -0
  213. package/dist/typescript/get-top-left-coordinates.d.ts +4 -0
  214. package/dist/typescript/get-top-left-coordinates.d.ts.map +1 -0
  215. package/dist/typescript/get-top-left-coordinates.js +36 -0
  216. package/dist/typescript/get-top-left-coordinates.js.map +1 -0
  217. package/dist/typescript/is-displayed.d.ts +1 -2
  218. package/dist/typescript/is-displayed.d.ts.map +1 -1
  219. package/dist/typescript/is-displayed.js +3 -396
  220. package/dist/typescript/is-displayed.js.map +1 -1
  221. package/dist/typescript/is-editable.d.ts +2 -0
  222. package/dist/typescript/is-editable.d.ts.map +1 -0
  223. package/dist/typescript/is-editable.js +18 -0
  224. package/dist/typescript/is-editable.js.map +1 -0
  225. package/dist/typescript/is-enabled.d.ts +2 -0
  226. package/dist/typescript/is-enabled.d.ts.map +1 -0
  227. package/dist/typescript/is-enabled.js +18 -0
  228. package/dist/typescript/is-enabled.js.map +1 -0
  229. package/dist/typescript/is-focusable.d.ts +2 -0
  230. package/dist/typescript/is-focusable.d.ts.map +1 -0
  231. package/dist/typescript/is-focusable.js +20 -0
  232. package/dist/typescript/is-focusable.js.map +1 -0
  233. package/dist/typescript/is-interactable.d.ts +2 -0
  234. package/dist/typescript/is-interactable.d.ts.map +1 -0
  235. package/dist/typescript/is-interactable.js +19 -0
  236. package/dist/typescript/is-interactable.js.map +1 -0
  237. package/dist/typescript/is-selected.d.ts +3 -0
  238. package/dist/typescript/is-selected.d.ts.map +1 -0
  239. package/dist/typescript/is-selected.js +29 -0
  240. package/dist/typescript/is-selected.js.map +1 -0
  241. package/dist/typescript/remove-local-storage-item.d.ts +3 -0
  242. package/dist/typescript/remove-local-storage-item.d.ts.map +1 -0
  243. package/dist/typescript/remove-local-storage-item.js +25 -0
  244. package/dist/typescript/remove-local-storage-item.js.map +1 -0
  245. package/dist/typescript/remove-session-storage-item.d.ts +3 -0
  246. package/dist/typescript/remove-session-storage-item.d.ts.map +1 -0
  247. package/dist/typescript/remove-session-storage-item.js +25 -0
  248. package/dist/typescript/remove-session-storage-item.js.map +1 -0
  249. package/dist/typescript/set-local-storage-item.d.ts +3 -0
  250. package/dist/typescript/set-local-storage-item.d.ts.map +1 -0
  251. package/dist/typescript/set-local-storage-item.js +26 -0
  252. package/dist/typescript/set-local-storage-item.js.map +1 -0
  253. package/dist/typescript/set-session-storage-item.d.ts +3 -0
  254. package/dist/typescript/set-session-storage-item.d.ts.map +1 -0
  255. package/dist/typescript/set-session-storage-item.js +26 -0
  256. package/dist/typescript/set-session-storage-item.js.map +1 -0
  257. package/dist/typescript/submit.d.ts +3 -0
  258. package/dist/typescript/submit.d.ts.map +1 -0
  259. package/dist/typescript/submit.js +50 -0
  260. package/dist/typescript/submit.js.map +1 -0
  261. package/dist/typescript/type.d.ts +3 -0
  262. package/dist/typescript/type.d.ts.map +1 -0
  263. package/dist/typescript/type.js +201 -0
  264. package/dist/typescript/type.js.map +1 -0
  265. package/index.ts +40 -0
  266. package/package.json +296 -5
  267. package/typescript/active-element.ts +19 -0
  268. package/typescript/clear-local-storage.ts +27 -0
  269. package/typescript/clear-session-storage.ts +27 -0
  270. package/typescript/clear.ts +73 -0
  271. package/typescript/click.ts +55 -0
  272. package/typescript/core/attribute.ts +68 -0
  273. package/typescript/core/color.ts +257 -0
  274. package/typescript/core/editable.ts +63 -0
  275. package/typescript/core/element.ts +110 -0
  276. package/typescript/core/enabled.ts +76 -0
  277. package/typescript/core/error.ts +41 -0
  278. package/typescript/core/events.ts +268 -0
  279. package/typescript/core/focus.ts +92 -0
  280. package/typescript/core/focusable.ts +38 -0
  281. package/typescript/core/form.ts +81 -0
  282. package/typescript/core/frame.ts +105 -0
  283. package/typescript/core/geometry.ts +183 -0
  284. package/typescript/core/inject.ts +336 -0
  285. package/typescript/core/interactable.ts +30 -0
  286. package/typescript/core/keyboard.ts +369 -0
  287. package/typescript/core/keys.ts +204 -0
  288. package/typescript/core/locators.ts +704 -0
  289. package/typescript/core/mouse.ts +211 -0
  290. package/typescript/core/overflow.ts +172 -0
  291. package/typescript/core/scroll.ts +92 -0
  292. package/typescript/core/shown.ts +233 -0
  293. package/typescript/core/storage.ts +111 -0
  294. package/typescript/core/style.ts +32 -0
  295. package/typescript/core/useragent.ts +33 -0
  296. package/typescript/default-content.ts +20 -0
  297. package/typescript/execute-async-script.ts +20 -0
  298. package/typescript/execute-script.ts +20 -0
  299. package/typescript/find-element-fragment.ts +45 -0
  300. package/typescript/find-element.ts +18 -0
  301. package/typescript/find-elements.ts +1 -326
  302. package/typescript/frame-by-id-or-name.ts +22 -0
  303. package/typescript/frame-by-index.ts +19 -0
  304. package/typescript/get-attribute-value.ts +22 -0
  305. package/typescript/get-effective-style.ts +93 -0
  306. package/typescript/get-element-from-cache.ts +20 -0
  307. package/typescript/get-frame-window.ts +22 -0
  308. package/typescript/get-local-storage-item.ts +27 -0
  309. package/typescript/get-local-storage-key.ts +28 -0
  310. package/typescript/get-local-storage-keys.ts +27 -0
  311. package/typescript/get-local-storage-size.ts +27 -0
  312. package/typescript/get-location.ts +63 -0
  313. package/typescript/get-session-storage-item.ts +27 -0
  314. package/typescript/get-session-storage-key.ts +28 -0
  315. package/typescript/get-session-storage-keys.ts +27 -0
  316. package/typescript/get-session-storage-size.ts +27 -0
  317. package/typescript/get-size.ts +43 -0
  318. package/typescript/get-text.ts +353 -0
  319. package/typescript/get-top-left-coordinates.ts +38 -0
  320. package/typescript/is-displayed.ts +3 -498
  321. package/typescript/is-editable.ts +18 -0
  322. package/typescript/is-enabled.ts +18 -0
  323. package/typescript/is-focusable.ts +20 -0
  324. package/typescript/is-interactable.ts +19 -0
  325. package/typescript/is-selected.ts +31 -0
  326. package/typescript/remove-local-storage-item.ts +27 -0
  327. package/typescript/remove-session-storage-item.ts +27 -0
  328. package/typescript/set-local-storage-item.ts +28 -0
  329. package/typescript/set-session-storage-item.ts +28 -0
  330. package/typescript/submit.ts +53 -0
  331. package/typescript/type.ts +210 -0
@@ -0,0 +1,268 @@
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
+ // Builds synthetic DOM events and dispatches them, for the interaction atoms.
19
+ //
20
+ // bot.events used document.createEvent + initMouseEvent, assigned key fields
21
+ // onto plain Events, and fired no pointer, beforeinput or mouseenter/leave
22
+ // events at all. This builds every event with its constructor so listeners
23
+ // see what real input gives them: key/code on key events, inputType/data on
24
+ // input events, buttons and a real click count on mouse events, pointer
25
+ // events, and `composed` set wherever the browser sets it -- without which a
26
+ // click inside a shadow root never reaches a document listener.
27
+ //
28
+ // What stays different from real input is unavoidable: isTrusted is false,
29
+ // and an untrusted event runs no default action except a click's activation
30
+ // behaviour, so the callers insert text and toggle options themselves.
31
+ //
32
+ // Not ported, with where they were used: touch (touchscreen), MSGesture /
33
+ // MSPointer (Internet Explorer), mouse wheel and MozMousePixelScroll
34
+ // (scrolling), orientationchange (touchscreen), propertychange (IE).
35
+
36
+ interface Modifiers {
37
+ altKey?: boolean
38
+ ctrlKey?: boolean
39
+ shiftKey?: boolean
40
+ metaKey?: boolean
41
+ }
42
+
43
+ export interface MouseArgs extends Modifiers {
44
+ clientX: number
45
+ clientY: number
46
+ button?: number
47
+ // The buttons held *after* this event, as the browser reports them: 1 on
48
+ // mousedown of the primary button, 0 on its mouseup.
49
+ buttons?: number
50
+ // The click count for click, mousedown and mouseup; 0 for the others.
51
+ detail?: number
52
+ relatedTarget?: EventTarget | null
53
+ }
54
+
55
+ export interface PointerArgs extends MouseArgs {
56
+ pointerId?: number
57
+ pointerType?: string
58
+ isPrimary?: boolean
59
+ }
60
+
61
+ export interface KeyboardArgs extends Modifiers {
62
+ key: string
63
+ code: string
64
+ // The legacy numbers are the caller's to choose: they differ by engine on
65
+ // keydown and keyup (Firefox reports 61 for '=', Chrome 187) and are the
66
+ // character code on keypress in both.
67
+ keyCode?: number
68
+ charCode?: number
69
+ location?: number
70
+ repeat?: boolean
71
+ }
72
+
73
+ export interface InputArgs {
74
+ inputType: string
75
+ data?: string | null
76
+ }
77
+
78
+ export interface TextArgs {
79
+ data: string
80
+ }
81
+
82
+ export interface FocusArgs {
83
+ relatedTarget?: EventTarget | null
84
+ }
85
+
86
+ export interface SubmitArgs {
87
+ submitter?: HTMLElement | null
88
+ }
89
+
90
+ type Target = Element | Document | Window
91
+
92
+ // goog.dom.getOwnerDocument: a document is its own owner.
93
+ function ownerDocument(target: Target): Document {
94
+ if ((target as Node).nodeType === Node.DOCUMENT_NODE) {
95
+ return target as Document
96
+ }
97
+ return (target as Element).ownerDocument || (target as Window).document
98
+ }
99
+
100
+ // Constructors come from the target's own window, so a listener in a frame
101
+ // that checks `event instanceof MouseEvent` sees its own realm's class.
102
+ function realm(target: Target): Window & typeof globalThis {
103
+ return (ownerDocument(target).defaultView || window) as Window & typeof globalThis
104
+ }
105
+
106
+ interface Shape {
107
+ bubbles: boolean
108
+ cancelable: boolean
109
+ composed: boolean
110
+ }
111
+
112
+ type Build<A> = (win: Window & typeof globalThis, type: string, shape: Shape, args: A) => Event
113
+
114
+ // One factory per event type. toString gives the DOM event name, so a factory
115
+ // can key a map or be handed to addEventListener-style code directly.
116
+ export class EventFactory<A = unknown> {
117
+ constructor(
118
+ private readonly type: string,
119
+ private readonly shape: Shape,
120
+ private readonly build: Build<A>,
121
+ ) {}
122
+
123
+ create(target: Target, args: A): Event {
124
+ return this.build(realm(target), this.type, this.shape, args)
125
+ }
126
+
127
+ toString(): string {
128
+ return this.type
129
+ }
130
+ }
131
+
132
+ function modifiers(args: Modifiers): Modifiers {
133
+ return {
134
+ altKey: !!args.altKey,
135
+ ctrlKey: !!args.ctrlKey,
136
+ shiftKey: !!args.shiftKey,
137
+ metaKey: !!args.metaKey,
138
+ }
139
+ }
140
+
141
+ // screenX/Y mirror clientX/Y. Not strictly correct, but pages under test
142
+ // depend on relative positions, which this preserves, and the true screen
143
+ // offset of the viewport is not knowable from script.
144
+ function mouseInit(win: Window, shape: Shape, args: MouseArgs): MouseEventInit {
145
+ return {
146
+ ...shape,
147
+ ...modifiers(args),
148
+ view: win,
149
+ detail: args.detail ?? 0,
150
+ clientX: args.clientX,
151
+ clientY: args.clientY,
152
+ screenX: args.clientX,
153
+ screenY: args.clientY,
154
+ button: args.button ?? 0,
155
+ buttons: args.buttons ?? 0,
156
+ relatedTarget: args.relatedTarget ?? null,
157
+ }
158
+ }
159
+
160
+ const plain: Build<unknown> = (win, type, shape) => new win.Event(type, shape)
161
+
162
+ const focus: Build<FocusArgs | undefined> = (win, type, shape, args) =>
163
+ new win.FocusEvent(type, { ...shape, view: win, relatedTarget: args?.relatedTarget ?? null })
164
+
165
+ const mouse: Build<MouseArgs> = (win, type, shape, args) => new win.MouseEvent(type, mouseInit(win, shape, args))
166
+
167
+ // A mouse's pointer: id 1, primary, 1x1, and the spec's 0.5 pressure while a
168
+ // button is held.
169
+ const pointer: Build<PointerArgs> = (win, type, shape, args) =>
170
+ new win.PointerEvent(type, {
171
+ ...mouseInit(win, shape, args),
172
+ pointerId: args.pointerId ?? 1,
173
+ pointerType: args.pointerType ?? 'mouse',
174
+ isPrimary: args.isPrimary ?? true,
175
+ width: 1,
176
+ height: 1,
177
+ pressure: args.buttons ? 0.5 : 0,
178
+ })
179
+
180
+ // keyCode, charCode and which are the legacy members of KeyboardEventInit;
181
+ // Chrome and Firefox both honour them.
182
+ const keyboard: Build<KeyboardArgs> = (win, type, shape, args) =>
183
+ new win.KeyboardEvent(type, {
184
+ ...shape,
185
+ ...modifiers(args),
186
+ view: win,
187
+ key: args.key,
188
+ code: args.code,
189
+ location: args.location ?? 0,
190
+ repeat: !!args.repeat,
191
+ keyCode: args.keyCode ?? 0,
192
+ charCode: args.charCode ?? 0,
193
+ which: args.keyCode || args.charCode || 0,
194
+ } as KeyboardEventInit)
195
+
196
+ const input: Build<InputArgs> = (win, type, shape, args) =>
197
+ new win.InputEvent(type, { ...shape, view: win, inputType: args.inputType, data: args.data ?? null })
198
+
199
+ // textInput is the legacy TextEvent, which has no constructor. Chrome, Firefox
200
+ // and Safari all still fire it between beforeinput and input, and some
201
+ // editors still listen for it.
202
+ const text: Build<TextArgs> = (win, type, shape, args) => {
203
+ const event = win.document.createEvent('TextEvent') as Event & {
204
+ initTextEvent(type: string, bubbles: boolean, cancelable: boolean, view: Window, data: string): void
205
+ }
206
+ event.initTextEvent(type, shape.bubbles, shape.cancelable, win, args.data)
207
+ return event
208
+ }
209
+
210
+ const submit: Build<SubmitArgs | undefined> = (win, type, shape, args) =>
211
+ new win.SubmitEvent(type, { ...shape, submitter: args?.submitter ?? null })
212
+
213
+ // Bubbles / cancelable / composed as UI Events, Pointer Events, Input Events
214
+ // and HTML define them for the real event.
215
+ function shape(bubbles: boolean, cancelable: boolean, composed: boolean): Shape {
216
+ return { bubbles, cancelable, composed }
217
+ }
218
+
219
+ const ui = shape(true, true, true)
220
+
221
+ export const EventType = {
222
+ CHANGE: new EventFactory('change', shape(true, false, false), plain),
223
+ SELECT: new EventFactory('select', shape(true, false, false), plain),
224
+ SUBMIT: new EventFactory('submit', shape(true, true, false), submit),
225
+
226
+ BLUR: new EventFactory('blur', shape(false, false, true), focus),
227
+ FOCUS: new EventFactory('focus', shape(false, false, true), focus),
228
+ FOCUSIN: new EventFactory('focusin', shape(true, false, true), focus),
229
+ FOCUSOUT: new EventFactory('focusout', shape(true, false, true), focus),
230
+
231
+ BEFOREINPUT: new EventFactory('beforeinput', ui, input),
232
+ INPUT: new EventFactory('input', shape(true, false, true), input),
233
+ TEXTINPUT: new EventFactory('textInput', shape(true, true, false), text),
234
+
235
+ KEYDOWN: new EventFactory('keydown', ui, keyboard),
236
+ KEYPRESS: new EventFactory('keypress', ui, keyboard),
237
+ KEYUP: new EventFactory('keyup', ui, keyboard),
238
+
239
+ CLICK: new EventFactory('click', ui, mouse),
240
+ CONTEXTMENU: new EventFactory('contextmenu', ui, mouse),
241
+ DBLCLICK: new EventFactory('dblclick', ui, mouse),
242
+ MOUSEDOWN: new EventFactory('mousedown', ui, mouse),
243
+ MOUSEMOVE: new EventFactory('mousemove', ui, mouse),
244
+ MOUSEOUT: new EventFactory('mouseout', ui, mouse),
245
+ MOUSEOVER: new EventFactory('mouseover', ui, mouse),
246
+ MOUSEUP: new EventFactory('mouseup', ui, mouse),
247
+ MOUSEENTER: new EventFactory('mouseenter', shape(false, false, false), mouse),
248
+ MOUSELEAVE: new EventFactory('mouseleave', shape(false, false, false), mouse),
249
+
250
+ POINTERDOWN: new EventFactory('pointerdown', ui, pointer),
251
+ POINTERMOVE: new EventFactory('pointermove', ui, pointer),
252
+ POINTEROUT: new EventFactory('pointerout', ui, pointer),
253
+ POINTEROVER: new EventFactory('pointerover', ui, pointer),
254
+ POINTERUP: new EventFactory('pointerup', ui, pointer),
255
+ POINTERENTER: new EventFactory('pointerenter', shape(false, false, false), pointer),
256
+ POINTERLEAVE: new EventFactory('pointerleave', shape(false, false, false), pointer),
257
+ }
258
+
259
+ // Whether the event went through uncancelled.
260
+ export function fire<A>(target: Target, type: EventFactory<A>, args: A): boolean {
261
+ return target.dispatchEvent(type.create(target, args))
262
+ }
263
+
264
+ // Dispatched events carry isTrusted: false, which is how a page tells them
265
+ // from real input.
266
+ export function isSynthetic(event: Event): boolean {
267
+ return !event.isTrusted
268
+ }
@@ -0,0 +1,92 @@
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
+ import { isElement } from './element.js'
19
+ import { isFocusable } from './focusable.js'
20
+
21
+ // The focused element, looking through open shadow roots: document.activeElement
22
+ // stops at the shadow host.
23
+ function getDeepActiveElement(doc: Document): Element | null {
24
+ return throughOpenShadowRoots(doc.activeElement)
25
+ }
26
+
27
+ // The focused element as seen from `element`. A closed shadow root hides its
28
+ // focused element from the document, but not from a node inside it: when
29
+ // focus is within the element's own shadow root, that root's active element
30
+ // is the true one, and the document would only report the host.
31
+ export function getActiveElementFrom(element: Element): Element | null {
32
+ const root = element.getRootNode() as Node & Partial<DocumentOrShadowRoot>
33
+ if (root !== element.ownerDocument && root.activeElement) {
34
+ return throughOpenShadowRoots(root.activeElement)
35
+ }
36
+ return getDeepActiveElement(element.ownerDocument)
37
+ }
38
+
39
+ // The focused element itself, or a shadow host whose tree holds focus: the
40
+ // one its own root reports as active. Keys already go to either, so typing
41
+ // into one needs no focusing or interactability check.
42
+ export function holdsFocus(element: Element): boolean {
43
+ const root = element.getRootNode() as Node & Partial<DocumentOrShadowRoot>
44
+ return element === getActiveElementFrom(element) || element === root.activeElement
45
+ }
46
+
47
+ function throughOpenShadowRoots(active: Element | null): Element | null {
48
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
49
+ active = active.shadowRoot.activeElement
50
+ }
51
+ return active
52
+ }
53
+
54
+ function focusTarget(element: Element): Element {
55
+ for (let node: Element | null = element; node; node = node.parentElement) {
56
+ if (isFocusable(node)) {
57
+ return node
58
+ }
59
+ }
60
+ return element
61
+ }
62
+
63
+ // Focuses the element, or its nearest focusable ancestor, as a click or a
64
+ // keyboard interaction would. Returns whether focus moved to it.
65
+ //
66
+ // focus() already blurs whatever had focus, so the explicit blur is only for
67
+ // a target that cannot take focus: a real click on non-focusable content
68
+ // still takes focus away from the field that had it. When focus lands
69
+ // somewhere else, a focus handler moved it there on purpose, so it is left
70
+ // alone. preventScroll because the caller has already scrolled the element
71
+ // into view and a second scroll would move it again.
72
+ export function focusOnElement(element: Element): boolean {
73
+ const target = focusTarget(element)
74
+ const previous = getActiveElementFrom(target)
75
+ if (previous === target) {
76
+ return false
77
+ }
78
+ if (typeof (target as HTMLElement).focus === 'function') {
79
+ ;(target as HTMLElement).focus({ preventScroll: true })
80
+ }
81
+ const active = getActiveElementFrom(target)
82
+ if (active === target) {
83
+ return true
84
+ }
85
+ if (active !== previous) {
86
+ return false
87
+ }
88
+ if (active && !isElement(active, 'BODY') && typeof (active as HTMLElement).blur === 'function') {
89
+ ;(active as HTMLElement).blur()
90
+ }
91
+ return false
92
+ }
@@ -0,0 +1,38 @@
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
+ import { getAttribute, getProperty } from './attribute.js'
19
+ import { isEditable } from './editable.js'
20
+ import { isElement } from './element.js'
21
+
22
+ // http://www.w3.org/TR/html401/interact/scripts.html#adef-onfocus
23
+ const FOCUSABLE_FORM_FIELDS = ['A', 'AREA', 'BUTTON', 'INPUT', 'LABEL', 'SELECT', 'TEXTAREA']
24
+
25
+ // An element can take focus if it is a form field, carries a non-negative
26
+ // tabindex, or is editable.
27
+ export function isFocusable(element: Element): boolean {
28
+ if (FOCUSABLE_FORM_FIELDS.some((tagName) => isElement(element, tagName))) {
29
+ return true
30
+ }
31
+ // The attribute has to be present for tabindex to count — the tabIndex
32
+ // property reports a default for several tags that were never marked up
33
+ // with one.
34
+ if (getAttribute(element, 'tabindex') != null && Number(getProperty(element, 'tabIndex')) >= 0) {
35
+ return true
36
+ }
37
+ return isEditable(element)
38
+ }
@@ -0,0 +1,81 @@
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
+ import { EventType, fire } from './events.js'
19
+
20
+ // <input> types that count against implicit submission (HTML, "implicit
21
+ // submission"): with more than one in the form and no submit button, Enter
22
+ // does not submit.
23
+ const BLOCKS_IMPLICIT_SUBMISSION = [
24
+ 'text',
25
+ 'search',
26
+ 'url',
27
+ 'tel',
28
+ 'email',
29
+ 'password',
30
+ 'date',
31
+ 'month',
32
+ 'week',
33
+ 'time',
34
+ 'datetime-local',
35
+ 'number',
36
+ ]
37
+
38
+ function isSubmitButton(element: Element): element is HTMLButtonElement | HTMLInputElement {
39
+ const type = (element as HTMLInputElement).type
40
+ if (element.tagName === 'BUTTON') {
41
+ return type === 'submit'
42
+ }
43
+ return element.tagName === 'INPUT' && (type === 'submit' || type === 'image')
44
+ }
45
+
46
+ // Enter in a form field, as HTML defines it: click the form's default button
47
+ // (its first submit button), which submits through the button's own
48
+ // activation behaviour; with no button, submit only if the field is the one
49
+ // field that would block it.
50
+ //
51
+ // This replaces bot.Keyboard.maybeSubmitForm_, which looked only at <input>s
52
+ // (so a <button type=submit> never counted), counted hidden and checkbox
53
+ // inputs as fields, and submitted with form.submit() -- skipping both the
54
+ // click on the default button and constraint validation, which real Enter
55
+ // runs.
56
+ export function implicitlySubmit(field: HTMLInputElement): void {
57
+ const form = field.form
58
+ if (!form) {
59
+ return
60
+ }
61
+ // Read through the prototype because a control named "elements" or
62
+ // "requestSubmit" shadows the form's own property.
63
+ const win = (form.ownerDocument.defaultView || window) as Window & typeof globalThis
64
+ const formPrototype = win.HTMLFormElement.prototype
65
+ const controls = Object.getOwnPropertyDescriptor(formPrototype, 'elements')!.get!.call(form) as HTMLFormControlsCollection
66
+ const elements = Array.from(controls)
67
+ const defaultButton = elements.find(isSubmitButton)
68
+ if (defaultButton) {
69
+ if (!defaultButton.disabled) {
70
+ // A keyboard-initiated click: no position and a click count of 0.
71
+ fire(defaultButton, EventType.CLICK, { clientX: 0, clientY: 0, detail: 0 })
72
+ }
73
+ return
74
+ }
75
+ const blocking = elements.filter(
76
+ (element) => element.tagName === 'INPUT' && BLOCKS_IMPLICIT_SUBMISSION.includes((element as HTMLInputElement).type),
77
+ )
78
+ if (blocking.length <= 1) {
79
+ formPrototype.requestSubmit.call(form)
80
+ }
81
+ }
@@ -0,0 +1,105 @@
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
+ import { isElement } from './element.js'
19
+ import { NO_SUCH_FRAME, botError } from './error.js'
20
+ import { findElements } from './locators.js'
21
+
22
+ // The window the atom is running in. Closure routed every one of these through
23
+ // bot.getWindow() because the inject layer retargets command execution at a
24
+ // frame; an atom called directly is already in the frame it is asking about.
25
+ function windowOr(optWindow?: Window): Window {
26
+ return optWindow || window
27
+ }
28
+
29
+ export function isFrame(element: Element): boolean {
30
+ return isElement(element, 'FRAME') || isElement(element, 'IFRAME')
31
+ }
32
+
33
+ // goog.dom.getFrameContentWindow. Returning null rather than propagating is
34
+ // the contract -- a frame that is detached, or whose document cannot be
35
+ // reached, is reported as "no window" rather than as a failure.
36
+ export function getFrameContentWindow(frame: HTMLIFrameElement | HTMLFrameElement): Window | null {
37
+ try {
38
+ return frame.contentWindow || (frame.contentDocument ? frame.contentDocument.defaultView : null)
39
+ } catch (_unreachable) {
40
+ return null
41
+ }
42
+ }
43
+
44
+ export function defaultContent(optWindow?: Window): Window | null {
45
+ return windowOr(optWindow).top
46
+ }
47
+
48
+ // Falls back to the body so that a document with nothing focused still answers
49
+ // with an element. bot.dom.getActiveElement is the other spelling of this and
50
+ // returns null instead; the frame one is what the active_element atom means.
51
+ export function activeElement(optWindow?: Window): Element {
52
+ const doc = windowOr(optWindow).document
53
+ return doc.activeElement || doc.body
54
+ }
55
+
56
+ export function getFrameWindow(element: Element): Window | null {
57
+ if (isFrame(element)) {
58
+ return getFrameContentWindow(element as HTMLIFrameElement | HTMLFrameElement)
59
+ }
60
+ throw botError(NO_SUCH_FRAME, "The given element isn't a frame or an iframe.")
61
+ }
62
+
63
+ // Name wins over id, despite the atom being called frame_by_id_or_name.
64
+ //
65
+ // Both lookups are deliberately shallow: frames[] holds only this window's own
66
+ // children and the id search runs over this window's document, so a nested or
67
+ // parent frame is not found from here. The Closure tests pin that -- searching
68
+ // the top window for a frame nested two levels down returns null.
69
+ //
70
+ // Inherited hazard: reading `name` off a cross-origin frame throws a
71
+ // SecurityError, because Window.name is not on the cross-origin allowlist.
72
+ // The Closure original has the same hole; it is not fixed here because that
73
+ // would be a behaviour change rather than a port. (frame.js:106)
74
+ export function findFrameByNameOrId(nameOrId: string | number, optRoot?: Window): Window | null {
75
+ const domWindow = windowOr(optRoot)
76
+
77
+ const numFrames = domWindow.frames.length
78
+ for (let i = 0; i < numFrames; i++) {
79
+ const frame = domWindow.frames[i]
80
+ // frameElement is the <frame>/<iframe> in the parent document, and null
81
+ // across an origin boundary, where the window itself carries the name.
82
+ const frameElement = frame.frameElement || frame
83
+ if ((frameElement as { name?: unknown }).name == nameOrId) {
84
+ // Safari 4 handed back an HTMLFrameElement here instead of a Window, so
85
+ // the original re-resolved it. Every supported browser gives a Window.
86
+ return frame
87
+ }
88
+ }
89
+
90
+ // bot.locators.id compared with ==, so a numeric id matched; the id locator
91
+ // here compares strings exactly.
92
+ const elements = findElements({ id: String(nameOrId) }, domWindow.document)
93
+ for (let i = 0; i < elements.length; i++) {
94
+ const frameElement = elements[i]
95
+ if (frameElement && isFrame(frameElement)) {
96
+ return getFrameContentWindow(frameElement as HTMLIFrameElement | HTMLFrameElement)
97
+ }
98
+ }
99
+
100
+ return null
101
+ }
102
+
103
+ export function findFrameByIndex(index: number, optRoot?: Window): Window | null {
104
+ return windowOr(optRoot).frames[index] || null
105
+ }