input.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. // Package input provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Input domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package input
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // DispatchDragEventParams dispatches a drag event into the page.
  12. type DispatchDragEventParams struct {
  13. Type DispatchDragEventType `json:"type"` // Type of the drag event.
  14. X float64 `json:"x"` // X coordinate of the event relative to the main frame's viewport in CSS pixels.
  15. Y float64 `json:"y"` // Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  16. Data *DragData `json:"data"`
  17. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  18. }
  19. // DispatchDragEvent dispatches a drag event into the page.
  20. //
  21. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchDragEvent
  22. //
  23. // parameters:
  24. //
  25. // type - Type of the drag event.
  26. // x - X coordinate of the event relative to the main frame's viewport in CSS pixels.
  27. // y - Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  28. // data
  29. func DispatchDragEvent(typeVal DispatchDragEventType, x float64, y float64, data *DragData) *DispatchDragEventParams {
  30. return &DispatchDragEventParams{
  31. Type: typeVal,
  32. X: x,
  33. Y: y,
  34. Data: data,
  35. }
  36. }
  37. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  38. // Meta/Command=4, Shift=8 (default: 0).
  39. func (p DispatchDragEventParams) WithModifiers(modifiers Modifier) *DispatchDragEventParams {
  40. p.Modifiers = modifiers
  41. return &p
  42. }
  43. // Do executes Input.dispatchDragEvent against the provided context.
  44. func (p *DispatchDragEventParams) Do(ctx context.Context) (err error) {
  45. return cdp.Execute(ctx, CommandDispatchDragEvent, p, nil)
  46. }
  47. // DispatchKeyEventParams dispatches a key event to the page.
  48. type DispatchKeyEventParams struct {
  49. Type KeyType `json:"type"` // Type of the key event.
  50. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  51. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty,omitzero"` // Time at which the event occurred.
  52. Text string `json:"text,omitempty,omitzero"` // Text as generated by processing a virtual key code with a keyboard layout. Not needed for for keyUp and rawKeyDown events (default: "")
  53. UnmodifiedText string `json:"unmodifiedText,omitempty,omitzero"` // Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: "").
  54. KeyIdentifier string `json:"keyIdentifier,omitempty,omitzero"` // Unique key identifier (e.g., 'U+0041') (default: "").
  55. Code string `json:"code,omitempty,omitzero"` // Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
  56. Key string `json:"key,omitempty,omitzero"` // Unique DOM defined string value describing the meaning of the key in the context of active modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
  57. WindowsVirtualKeyCode int64 `json:"windowsVirtualKeyCode,omitempty,omitzero"` // Windows virtual key code (default: 0).
  58. NativeVirtualKeyCode int64 `json:"nativeVirtualKeyCode,omitempty,omitzero"` // Native virtual key code (default: 0).
  59. AutoRepeat bool `json:"autoRepeat"` // Whether the event was generated from auto repeat (default: false).
  60. IsKeypad bool `json:"isKeypad"` // Whether the event was generated from the keypad (default: false).
  61. IsSystemKey bool `json:"isSystemKey"` // Whether the event was a system key event (default: false).
  62. Location int64 `json:"location,omitempty,omitzero"` // Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default: 0).
  63. Commands []string `json:"commands,omitempty,omitzero"` // Editing commands to send with the key event (e.g., 'selectAll') (default: []). These are related to but not equal the command names used in document.execCommand and NSStandardKeyBindingResponding. See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h for valid command names.
  64. }
  65. // DispatchKeyEvent dispatches a key event to the page.
  66. //
  67. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchKeyEvent
  68. //
  69. // parameters:
  70. //
  71. // type - Type of the key event.
  72. func DispatchKeyEvent(typeVal KeyType) *DispatchKeyEventParams {
  73. return &DispatchKeyEventParams{
  74. Type: typeVal,
  75. AutoRepeat: false,
  76. IsKeypad: false,
  77. IsSystemKey: false,
  78. }
  79. }
  80. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  81. // Meta/Command=4, Shift=8 (default: 0).
  82. func (p DispatchKeyEventParams) WithModifiers(modifiers Modifier) *DispatchKeyEventParams {
  83. p.Modifiers = modifiers
  84. return &p
  85. }
  86. // WithTimestamp time at which the event occurred.
  87. func (p DispatchKeyEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchKeyEventParams {
  88. p.Timestamp = timestamp
  89. return &p
  90. }
  91. // WithText text as generated by processing a virtual key code with a
  92. // keyboard layout. Not needed for for keyUp and rawKeyDown events (default:
  93. // "").
  94. func (p DispatchKeyEventParams) WithText(text string) *DispatchKeyEventParams {
  95. p.Text = text
  96. return &p
  97. }
  98. // WithUnmodifiedText text that would have been generated by the keyboard if
  99. // no modifiers were pressed (except for shift). Useful for shortcut
  100. // (accelerator) key handling (default: "").
  101. func (p DispatchKeyEventParams) WithUnmodifiedText(unmodifiedText string) *DispatchKeyEventParams {
  102. p.UnmodifiedText = unmodifiedText
  103. return &p
  104. }
  105. // WithKeyIdentifier unique key identifier (e.g., 'U+0041') (default: "").
  106. func (p DispatchKeyEventParams) WithKeyIdentifier(keyIdentifier string) *DispatchKeyEventParams {
  107. p.KeyIdentifier = keyIdentifier
  108. return &p
  109. }
  110. // WithCode unique DOM defined string value for each physical key (e.g.,
  111. // 'KeyA') (default: "").
  112. func (p DispatchKeyEventParams) WithCode(code string) *DispatchKeyEventParams {
  113. p.Code = code
  114. return &p
  115. }
  116. // WithKey unique DOM defined string value describing the meaning of the key
  117. // in the context of active modifiers, keyboard layout, etc (e.g., 'AltGr')
  118. // (default: "").
  119. func (p DispatchKeyEventParams) WithKey(key string) *DispatchKeyEventParams {
  120. p.Key = key
  121. return &p
  122. }
  123. // WithWindowsVirtualKeyCode windows virtual key code (default: 0).
  124. func (p DispatchKeyEventParams) WithWindowsVirtualKeyCode(windowsVirtualKeyCode int64) *DispatchKeyEventParams {
  125. p.WindowsVirtualKeyCode = windowsVirtualKeyCode
  126. return &p
  127. }
  128. // WithNativeVirtualKeyCode native virtual key code (default: 0).
  129. func (p DispatchKeyEventParams) WithNativeVirtualKeyCode(nativeVirtualKeyCode int64) *DispatchKeyEventParams {
  130. p.NativeVirtualKeyCode = nativeVirtualKeyCode
  131. return &p
  132. }
  133. // WithAutoRepeat whether the event was generated from auto repeat (default:
  134. // false).
  135. func (p DispatchKeyEventParams) WithAutoRepeat(autoRepeat bool) *DispatchKeyEventParams {
  136. p.AutoRepeat = autoRepeat
  137. return &p
  138. }
  139. // WithIsKeypad whether the event was generated from the keypad (default:
  140. // false).
  141. func (p DispatchKeyEventParams) WithIsKeypad(isKeypad bool) *DispatchKeyEventParams {
  142. p.IsKeypad = isKeypad
  143. return &p
  144. }
  145. // WithIsSystemKey whether the event was a system key event (default: false).
  146. func (p DispatchKeyEventParams) WithIsSystemKey(isSystemKey bool) *DispatchKeyEventParams {
  147. p.IsSystemKey = isSystemKey
  148. return &p
  149. }
  150. // WithLocation whether the event was from the left or right side of the
  151. // keyboard. 1=Left, 2=Right (default: 0).
  152. func (p DispatchKeyEventParams) WithLocation(location int64) *DispatchKeyEventParams {
  153. p.Location = location
  154. return &p
  155. }
  156. // WithCommands editing commands to send with the key event (e.g.,
  157. // 'selectAll') (default: []). These are related to but not equal the command
  158. // names used in document.execCommand and NSStandardKeyBindingResponding. See
  159. // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h
  160. // for valid command names.
  161. func (p DispatchKeyEventParams) WithCommands(commands []string) *DispatchKeyEventParams {
  162. p.Commands = commands
  163. return &p
  164. }
  165. // Do executes Input.dispatchKeyEvent against the provided context.
  166. func (p *DispatchKeyEventParams) Do(ctx context.Context) (err error) {
  167. return cdp.Execute(ctx, CommandDispatchKeyEvent, p, nil)
  168. }
  169. // InsertTextParams this method emulates inserting text that doesn't come
  170. // from a key press, for example an emoji keyboard or an IME.
  171. type InsertTextParams struct {
  172. Text string `json:"text"` // The text to insert.
  173. }
  174. // InsertText this method emulates inserting text that doesn't come from a
  175. // key press, for example an emoji keyboard or an IME.
  176. //
  177. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-insertText
  178. //
  179. // parameters:
  180. //
  181. // text - The text to insert.
  182. func InsertText(text string) *InsertTextParams {
  183. return &InsertTextParams{
  184. Text: text,
  185. }
  186. }
  187. // Do executes Input.insertText against the provided context.
  188. func (p *InsertTextParams) Do(ctx context.Context) (err error) {
  189. return cdp.Execute(ctx, CommandInsertText, p, nil)
  190. }
  191. // ImeSetCompositionParams this method sets the current candidate text for
  192. // IME. Use imeCommitComposition to commit the final text. Use imeSetComposition
  193. // with empty string as text to cancel composition.
  194. type ImeSetCompositionParams struct {
  195. Text string `json:"text"` // The text to insert
  196. SelectionStart int64 `json:"selectionStart"` // selection start
  197. SelectionEnd int64 `json:"selectionEnd"` // selection end
  198. ReplacementStart int64 `json:"replacementStart,omitempty,omitzero"` // replacement start
  199. ReplacementEnd int64 `json:"replacementEnd,omitempty,omitzero"` // replacement end
  200. }
  201. // ImeSetComposition this method sets the current candidate text for IME. Use
  202. // imeCommitComposition to commit the final text. Use imeSetComposition with
  203. // empty string as text to cancel composition.
  204. //
  205. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-imeSetComposition
  206. //
  207. // parameters:
  208. //
  209. // text - The text to insert
  210. // selectionStart - selection start
  211. // selectionEnd - selection end
  212. func ImeSetComposition(text string, selectionStart int64, selectionEnd int64) *ImeSetCompositionParams {
  213. return &ImeSetCompositionParams{
  214. Text: text,
  215. SelectionStart: selectionStart,
  216. SelectionEnd: selectionEnd,
  217. }
  218. }
  219. // WithReplacementStart replacement start.
  220. func (p ImeSetCompositionParams) WithReplacementStart(replacementStart int64) *ImeSetCompositionParams {
  221. p.ReplacementStart = replacementStart
  222. return &p
  223. }
  224. // WithReplacementEnd replacement end.
  225. func (p ImeSetCompositionParams) WithReplacementEnd(replacementEnd int64) *ImeSetCompositionParams {
  226. p.ReplacementEnd = replacementEnd
  227. return &p
  228. }
  229. // Do executes Input.imeSetComposition against the provided context.
  230. func (p *ImeSetCompositionParams) Do(ctx context.Context) (err error) {
  231. return cdp.Execute(ctx, CommandImeSetComposition, p, nil)
  232. }
  233. // DispatchMouseEventParams dispatches a mouse event to the page.
  234. type DispatchMouseEventParams struct {
  235. Type MouseType `json:"type"` // Type of the mouse event.
  236. X float64 `json:"x"` // X coordinate of the event relative to the main frame's viewport in CSS pixels.
  237. Y float64 `json:"y"` // Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  238. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  239. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty,omitzero"` // Time at which the event occurred.
  240. Button MouseButton `json:"button,omitempty,omitzero"` // Mouse button (default: "none").
  241. Buttons int64 `json:"buttons,omitempty,omitzero"` // A number indicating which buttons are pressed on the mouse when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
  242. ClickCount int64 `json:"clickCount,omitempty,omitzero"` // Number of times the mouse button was clicked (default: 0).
  243. Force float64 `json:"force,omitempty,omitzero"` // The normalized pressure, which has a range of [0,1] (default: 0).
  244. TangentialPressure float64 `json:"tangentialPressure,omitempty,omitzero"` // The normalized tangential pressure, which has a range of [-1,1] (default: 0).
  245. TiltX float64 `json:"tiltX,omitempty,omitzero"` // The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0).
  246. TiltY float64 `json:"tiltY,omitempty,omitzero"` // The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).
  247. Twist int64 `json:"twist,omitempty,omitzero"` // The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).
  248. DeltaX float64 `json:"deltaX"` // X delta in CSS pixels for mouse wheel event (default: 0).
  249. DeltaY float64 `json:"deltaY"` // Y delta in CSS pixels for mouse wheel event (default: 0).
  250. PointerType DispatchMouseEventPointerType `json:"pointerType,omitempty,omitzero"` // Pointer type (default: "mouse").
  251. }
  252. // DispatchMouseEvent dispatches a mouse event to the page.
  253. //
  254. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchMouseEvent
  255. //
  256. // parameters:
  257. //
  258. // type - Type of the mouse event.
  259. // x - X coordinate of the event relative to the main frame's viewport in CSS pixels.
  260. // y - Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  261. func DispatchMouseEvent(typeVal MouseType, x float64, y float64) *DispatchMouseEventParams {
  262. return &DispatchMouseEventParams{
  263. Type: typeVal,
  264. X: x,
  265. Y: y,
  266. }
  267. }
  268. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  269. // Meta/Command=4, Shift=8 (default: 0).
  270. func (p DispatchMouseEventParams) WithModifiers(modifiers Modifier) *DispatchMouseEventParams {
  271. p.Modifiers = modifiers
  272. return &p
  273. }
  274. // WithTimestamp time at which the event occurred.
  275. func (p DispatchMouseEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchMouseEventParams {
  276. p.Timestamp = timestamp
  277. return &p
  278. }
  279. // WithButton mouse button (default: "none").
  280. func (p DispatchMouseEventParams) WithButton(button MouseButton) *DispatchMouseEventParams {
  281. p.Button = button
  282. return &p
  283. }
  284. // WithButtons a number indicating which buttons are pressed on the mouse
  285. // when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8,
  286. // Forward=16, None=0.
  287. func (p DispatchMouseEventParams) WithButtons(buttons int64) *DispatchMouseEventParams {
  288. p.Buttons = buttons
  289. return &p
  290. }
  291. // WithClickCount number of times the mouse button was clicked (default: 0).
  292. func (p DispatchMouseEventParams) WithClickCount(clickCount int64) *DispatchMouseEventParams {
  293. p.ClickCount = clickCount
  294. return &p
  295. }
  296. // WithForce the normalized pressure, which has a range of [0,1] (default:
  297. // 0).
  298. func (p DispatchMouseEventParams) WithForce(force float64) *DispatchMouseEventParams {
  299. p.Force = force
  300. return &p
  301. }
  302. // WithTangentialPressure the normalized tangential pressure, which has a
  303. // range of [-1,1] (default: 0).
  304. func (p DispatchMouseEventParams) WithTangentialPressure(tangentialPressure float64) *DispatchMouseEventParams {
  305. p.TangentialPressure = tangentialPressure
  306. return &p
  307. }
  308. // WithTiltX the plane angle between the Y-Z plane and the plane containing
  309. // both the stylus axis and the Y axis, in degrees of the range [-90,90], a
  310. // positive tiltX is to the right (default: 0).
  311. func (p DispatchMouseEventParams) WithTiltX(tiltX float64) *DispatchMouseEventParams {
  312. p.TiltX = tiltX
  313. return &p
  314. }
  315. // WithTiltY the plane angle between the X-Z plane and the plane containing
  316. // both the stylus axis and the X axis, in degrees of the range [-90,90], a
  317. // positive tiltY is towards the user (default: 0).
  318. func (p DispatchMouseEventParams) WithTiltY(tiltY float64) *DispatchMouseEventParams {
  319. p.TiltY = tiltY
  320. return &p
  321. }
  322. // WithTwist the clockwise rotation of a pen stylus around its own major
  323. // axis, in degrees in the range [0,359] (default: 0).
  324. func (p DispatchMouseEventParams) WithTwist(twist int64) *DispatchMouseEventParams {
  325. p.Twist = twist
  326. return &p
  327. }
  328. // WithDeltaX X delta in CSS pixels for mouse wheel event (default: 0).
  329. func (p DispatchMouseEventParams) WithDeltaX(deltaX float64) *DispatchMouseEventParams {
  330. p.DeltaX = deltaX
  331. return &p
  332. }
  333. // WithDeltaY Y delta in CSS pixels for mouse wheel event (default: 0).
  334. func (p DispatchMouseEventParams) WithDeltaY(deltaY float64) *DispatchMouseEventParams {
  335. p.DeltaY = deltaY
  336. return &p
  337. }
  338. // WithPointerType pointer type (default: "mouse").
  339. func (p DispatchMouseEventParams) WithPointerType(pointerType DispatchMouseEventPointerType) *DispatchMouseEventParams {
  340. p.PointerType = pointerType
  341. return &p
  342. }
  343. // Do executes Input.dispatchMouseEvent against the provided context.
  344. func (p *DispatchMouseEventParams) Do(ctx context.Context) (err error) {
  345. return cdp.Execute(ctx, CommandDispatchMouseEvent, p, nil)
  346. }
  347. // DispatchTouchEventParams dispatches a touch event to the page.
  348. type DispatchTouchEventParams struct {
  349. Type TouchType `json:"type"` // Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.
  350. TouchPoints []*TouchPoint `json:"touchPoints"` // Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.
  351. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  352. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty,omitzero"` // Time at which the event occurred.
  353. }
  354. // DispatchTouchEvent dispatches a touch event to the page.
  355. //
  356. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-dispatchTouchEvent
  357. //
  358. // parameters:
  359. //
  360. // type - Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.
  361. // touchPoints - Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.
  362. func DispatchTouchEvent(typeVal TouchType, touchPoints []*TouchPoint) *DispatchTouchEventParams {
  363. return &DispatchTouchEventParams{
  364. Type: typeVal,
  365. TouchPoints: touchPoints,
  366. }
  367. }
  368. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  369. // Meta/Command=4, Shift=8 (default: 0).
  370. func (p DispatchTouchEventParams) WithModifiers(modifiers Modifier) *DispatchTouchEventParams {
  371. p.Modifiers = modifiers
  372. return &p
  373. }
  374. // WithTimestamp time at which the event occurred.
  375. func (p DispatchTouchEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *DispatchTouchEventParams {
  376. p.Timestamp = timestamp
  377. return &p
  378. }
  379. // Do executes Input.dispatchTouchEvent against the provided context.
  380. func (p *DispatchTouchEventParams) Do(ctx context.Context) (err error) {
  381. return cdp.Execute(ctx, CommandDispatchTouchEvent, p, nil)
  382. }
  383. // CancelDraggingParams cancels any active dragging in the page.
  384. type CancelDraggingParams struct{}
  385. // CancelDragging cancels any active dragging in the page.
  386. //
  387. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-cancelDragging
  388. func CancelDragging() *CancelDraggingParams {
  389. return &CancelDraggingParams{}
  390. }
  391. // Do executes Input.cancelDragging against the provided context.
  392. func (p *CancelDraggingParams) Do(ctx context.Context) (err error) {
  393. return cdp.Execute(ctx, CommandCancelDragging, nil, nil)
  394. }
  395. // EmulateTouchFromMouseEventParams emulates touch event from the mouse event
  396. // parameters.
  397. type EmulateTouchFromMouseEventParams struct {
  398. Type MouseType `json:"type"` // Type of the mouse event.
  399. X int64 `json:"x"` // X coordinate of the mouse pointer in DIP.
  400. Y int64 `json:"y"` // Y coordinate of the mouse pointer in DIP.
  401. Button MouseButton `json:"button"` // Mouse button. Only "none", "left", "right" are supported.
  402. Timestamp *TimeSinceEpoch `json:"timestamp,omitempty,omitzero"` // Time at which the event occurred (default: current time).
  403. DeltaX float64 `json:"deltaX"` // X delta in DIP for mouse wheel event (default: 0).
  404. DeltaY float64 `json:"deltaY"` // Y delta in DIP for mouse wheel event (default: 0).
  405. Modifiers Modifier `json:"modifiers"` // Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  406. ClickCount int64 `json:"clickCount,omitempty,omitzero"` // Number of times the mouse button was clicked (default: 0).
  407. }
  408. // EmulateTouchFromMouseEvent emulates touch event from the mouse event
  409. // parameters.
  410. //
  411. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-emulateTouchFromMouseEvent
  412. //
  413. // parameters:
  414. //
  415. // type - Type of the mouse event.
  416. // x - X coordinate of the mouse pointer in DIP.
  417. // y - Y coordinate of the mouse pointer in DIP.
  418. // button - Mouse button. Only "none", "left", "right" are supported.
  419. func EmulateTouchFromMouseEvent(typeVal MouseType, x int64, y int64, button MouseButton) *EmulateTouchFromMouseEventParams {
  420. return &EmulateTouchFromMouseEventParams{
  421. Type: typeVal,
  422. X: x,
  423. Y: y,
  424. Button: button,
  425. }
  426. }
  427. // WithTimestamp time at which the event occurred (default: current time).
  428. func (p EmulateTouchFromMouseEventParams) WithTimestamp(timestamp *TimeSinceEpoch) *EmulateTouchFromMouseEventParams {
  429. p.Timestamp = timestamp
  430. return &p
  431. }
  432. // WithDeltaX X delta in DIP for mouse wheel event (default: 0).
  433. func (p EmulateTouchFromMouseEventParams) WithDeltaX(deltaX float64) *EmulateTouchFromMouseEventParams {
  434. p.DeltaX = deltaX
  435. return &p
  436. }
  437. // WithDeltaY Y delta in DIP for mouse wheel event (default: 0).
  438. func (p EmulateTouchFromMouseEventParams) WithDeltaY(deltaY float64) *EmulateTouchFromMouseEventParams {
  439. p.DeltaY = deltaY
  440. return &p
  441. }
  442. // WithModifiers bit field representing pressed modifier keys. Alt=1, Ctrl=2,
  443. // Meta/Command=4, Shift=8 (default: 0).
  444. func (p EmulateTouchFromMouseEventParams) WithModifiers(modifiers Modifier) *EmulateTouchFromMouseEventParams {
  445. p.Modifiers = modifiers
  446. return &p
  447. }
  448. // WithClickCount number of times the mouse button was clicked (default: 0).
  449. func (p EmulateTouchFromMouseEventParams) WithClickCount(clickCount int64) *EmulateTouchFromMouseEventParams {
  450. p.ClickCount = clickCount
  451. return &p
  452. }
  453. // Do executes Input.emulateTouchFromMouseEvent against the provided context.
  454. func (p *EmulateTouchFromMouseEventParams) Do(ctx context.Context) (err error) {
  455. return cdp.Execute(ctx, CommandEmulateTouchFromMouseEvent, p, nil)
  456. }
  457. // SetIgnoreInputEventsParams ignores input events (useful while auditing
  458. // page).
  459. type SetIgnoreInputEventsParams struct {
  460. Ignore bool `json:"ignore"` // Ignores input events processing when set to true.
  461. }
  462. // SetIgnoreInputEvents ignores input events (useful while auditing page).
  463. //
  464. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-setIgnoreInputEvents
  465. //
  466. // parameters:
  467. //
  468. // ignore - Ignores input events processing when set to true.
  469. func SetIgnoreInputEvents(ignore bool) *SetIgnoreInputEventsParams {
  470. return &SetIgnoreInputEventsParams{
  471. Ignore: ignore,
  472. }
  473. }
  474. // Do executes Input.setIgnoreInputEvents against the provided context.
  475. func (p *SetIgnoreInputEventsParams) Do(ctx context.Context) (err error) {
  476. return cdp.Execute(ctx, CommandSetIgnoreInputEvents, p, nil)
  477. }
  478. // SetInterceptDragsParams prevents default drag and drop behavior and
  479. // instead emits Input.dragIntercepted events. Drag and drop behavior can be
  480. // directly controlled via Input.dispatchDragEvent.
  481. type SetInterceptDragsParams struct {
  482. Enabled bool `json:"enabled"`
  483. }
  484. // SetInterceptDrags prevents default drag and drop behavior and instead
  485. // emits Input.dragIntercepted events. Drag and drop behavior can be directly
  486. // controlled via Input.dispatchDragEvent.
  487. //
  488. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-setInterceptDrags
  489. //
  490. // parameters:
  491. //
  492. // enabled
  493. func SetInterceptDrags(enabled bool) *SetInterceptDragsParams {
  494. return &SetInterceptDragsParams{
  495. Enabled: enabled,
  496. }
  497. }
  498. // Do executes Input.setInterceptDrags against the provided context.
  499. func (p *SetInterceptDragsParams) Do(ctx context.Context) (err error) {
  500. return cdp.Execute(ctx, CommandSetInterceptDrags, p, nil)
  501. }
  502. // SynthesizePinchGestureParams synthesizes a pinch gesture over a time
  503. // period by issuing appropriate touch events.
  504. type SynthesizePinchGestureParams struct {
  505. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  506. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  507. ScaleFactor float64 `json:"scaleFactor"` // Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
  508. RelativeSpeed int64 `json:"relativeSpeed,omitempty,omitzero"` // Relative pointer speed in pixels per second (default: 800).
  509. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty,omitzero"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  510. }
  511. // SynthesizePinchGesture synthesizes a pinch gesture over a time period by
  512. // issuing appropriate touch events.
  513. //
  514. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizePinchGesture
  515. //
  516. // parameters:
  517. //
  518. // x - X coordinate of the start of the gesture in CSS pixels.
  519. // y - Y coordinate of the start of the gesture in CSS pixels.
  520. // scaleFactor - Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
  521. func SynthesizePinchGesture(x float64, y float64, scaleFactor float64) *SynthesizePinchGestureParams {
  522. return &SynthesizePinchGestureParams{
  523. X: x,
  524. Y: y,
  525. ScaleFactor: scaleFactor,
  526. }
  527. }
  528. // WithRelativeSpeed relative pointer speed in pixels per second (default:
  529. // 800).
  530. func (p SynthesizePinchGestureParams) WithRelativeSpeed(relativeSpeed int64) *SynthesizePinchGestureParams {
  531. p.RelativeSpeed = relativeSpeed
  532. return &p
  533. }
  534. // WithGestureSourceType which type of input events to be generated (default:
  535. // 'default', which queries the platform for the preferred input type).
  536. func (p SynthesizePinchGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizePinchGestureParams {
  537. p.GestureSourceType = gestureSourceType
  538. return &p
  539. }
  540. // Do executes Input.synthesizePinchGesture against the provided context.
  541. func (p *SynthesizePinchGestureParams) Do(ctx context.Context) (err error) {
  542. return cdp.Execute(ctx, CommandSynthesizePinchGesture, p, nil)
  543. }
  544. // SynthesizeScrollGestureParams synthesizes a scroll gesture over a time
  545. // period by issuing appropriate touch events.
  546. type SynthesizeScrollGestureParams struct {
  547. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  548. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  549. XDistance float64 `json:"xDistance,omitempty,omitzero"` // The distance to scroll along the X axis (positive to scroll left).
  550. YDistance float64 `json:"yDistance,omitempty,omitzero"` // The distance to scroll along the Y axis (positive to scroll up).
  551. XOverscroll float64 `json:"xOverscroll,omitempty,omitzero"` // The number of additional pixels to scroll back along the X axis, in addition to the given distance.
  552. YOverscroll float64 `json:"yOverscroll,omitempty,omitzero"` // The number of additional pixels to scroll back along the Y axis, in addition to the given distance.
  553. PreventFling bool `json:"preventFling"` // Prevent fling (default: true).
  554. Speed int64 `json:"speed,omitempty,omitzero"` // Swipe speed in pixels per second (default: 800).
  555. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty,omitzero"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  556. RepeatCount int64 `json:"repeatCount,omitempty,omitzero"` // The number of times to repeat the gesture (default: 0).
  557. RepeatDelayMs int64 `json:"repeatDelayMs,omitempty,omitzero"` // The number of milliseconds delay between each repeat. (default: 250).
  558. InteractionMarkerName string `json:"interactionMarkerName,omitempty,omitzero"` // The name of the interaction markers to generate, if not empty (default: "").
  559. }
  560. // SynthesizeScrollGesture synthesizes a scroll gesture over a time period by
  561. // issuing appropriate touch events.
  562. //
  563. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizeScrollGesture
  564. //
  565. // parameters:
  566. //
  567. // x - X coordinate of the start of the gesture in CSS pixels.
  568. // y - Y coordinate of the start of the gesture in CSS pixels.
  569. func SynthesizeScrollGesture(x float64, y float64) *SynthesizeScrollGestureParams {
  570. return &SynthesizeScrollGestureParams{
  571. X: x,
  572. Y: y,
  573. PreventFling: true,
  574. }
  575. }
  576. // WithXDistance the distance to scroll along the X axis (positive to scroll
  577. // left).
  578. func (p SynthesizeScrollGestureParams) WithXDistance(xDistance float64) *SynthesizeScrollGestureParams {
  579. p.XDistance = xDistance
  580. return &p
  581. }
  582. // WithYDistance the distance to scroll along the Y axis (positive to scroll
  583. // up).
  584. func (p SynthesizeScrollGestureParams) WithYDistance(yDistance float64) *SynthesizeScrollGestureParams {
  585. p.YDistance = yDistance
  586. return &p
  587. }
  588. // WithXOverscroll the number of additional pixels to scroll back along the X
  589. // axis, in addition to the given distance.
  590. func (p SynthesizeScrollGestureParams) WithXOverscroll(xOverscroll float64) *SynthesizeScrollGestureParams {
  591. p.XOverscroll = xOverscroll
  592. return &p
  593. }
  594. // WithYOverscroll the number of additional pixels to scroll back along the Y
  595. // axis, in addition to the given distance.
  596. func (p SynthesizeScrollGestureParams) WithYOverscroll(yOverscroll float64) *SynthesizeScrollGestureParams {
  597. p.YOverscroll = yOverscroll
  598. return &p
  599. }
  600. // WithPreventFling prevent fling (default: true).
  601. func (p SynthesizeScrollGestureParams) WithPreventFling(preventFling bool) *SynthesizeScrollGestureParams {
  602. p.PreventFling = preventFling
  603. return &p
  604. }
  605. // WithSpeed swipe speed in pixels per second (default: 800).
  606. func (p SynthesizeScrollGestureParams) WithSpeed(speed int64) *SynthesizeScrollGestureParams {
  607. p.Speed = speed
  608. return &p
  609. }
  610. // WithGestureSourceType which type of input events to be generated (default:
  611. // 'default', which queries the platform for the preferred input type).
  612. func (p SynthesizeScrollGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizeScrollGestureParams {
  613. p.GestureSourceType = gestureSourceType
  614. return &p
  615. }
  616. // WithRepeatCount the number of times to repeat the gesture (default: 0).
  617. func (p SynthesizeScrollGestureParams) WithRepeatCount(repeatCount int64) *SynthesizeScrollGestureParams {
  618. p.RepeatCount = repeatCount
  619. return &p
  620. }
  621. // WithRepeatDelayMs the number of milliseconds delay between each repeat.
  622. // (default: 250).
  623. func (p SynthesizeScrollGestureParams) WithRepeatDelayMs(repeatDelayMs int64) *SynthesizeScrollGestureParams {
  624. p.RepeatDelayMs = repeatDelayMs
  625. return &p
  626. }
  627. // WithInteractionMarkerName the name of the interaction markers to generate,
  628. // if not empty (default: "").
  629. func (p SynthesizeScrollGestureParams) WithInteractionMarkerName(interactionMarkerName string) *SynthesizeScrollGestureParams {
  630. p.InteractionMarkerName = interactionMarkerName
  631. return &p
  632. }
  633. // Do executes Input.synthesizeScrollGesture against the provided context.
  634. func (p *SynthesizeScrollGestureParams) Do(ctx context.Context) (err error) {
  635. return cdp.Execute(ctx, CommandSynthesizeScrollGesture, p, nil)
  636. }
  637. // SynthesizeTapGestureParams synthesizes a tap gesture over a time period by
  638. // issuing appropriate touch events.
  639. type SynthesizeTapGestureParams struct {
  640. X float64 `json:"x"` // X coordinate of the start of the gesture in CSS pixels.
  641. Y float64 `json:"y"` // Y coordinate of the start of the gesture in CSS pixels.
  642. Duration int64 `json:"duration,omitempty,omitzero"` // Duration between touchdown and touchup events in ms (default: 50).
  643. TapCount int64 `json:"tapCount,omitempty,omitzero"` // Number of times to perform the tap (e.g. 2 for double tap, default: 1).
  644. GestureSourceType GestureSourceType `json:"gestureSourceType,omitempty,omitzero"` // Which type of input events to be generated (default: 'default', which queries the platform for the preferred input type).
  645. }
  646. // SynthesizeTapGesture synthesizes a tap gesture over a time period by
  647. // issuing appropriate touch events.
  648. //
  649. // See: https://chromedevtools.github.io/devtools-protocol/tot/Input#method-synthesizeTapGesture
  650. //
  651. // parameters:
  652. //
  653. // x - X coordinate of the start of the gesture in CSS pixels.
  654. // y - Y coordinate of the start of the gesture in CSS pixels.
  655. func SynthesizeTapGesture(x float64, y float64) *SynthesizeTapGestureParams {
  656. return &SynthesizeTapGestureParams{
  657. X: x,
  658. Y: y,
  659. }
  660. }
  661. // WithDuration duration between touchdown and touchup events in ms (default:
  662. // 50).
  663. func (p SynthesizeTapGestureParams) WithDuration(duration int64) *SynthesizeTapGestureParams {
  664. p.Duration = duration
  665. return &p
  666. }
  667. // WithTapCount number of times to perform the tap (e.g. 2 for double tap,
  668. // default: 1).
  669. func (p SynthesizeTapGestureParams) WithTapCount(tapCount int64) *SynthesizeTapGestureParams {
  670. p.TapCount = tapCount
  671. return &p
  672. }
  673. // WithGestureSourceType which type of input events to be generated (default:
  674. // 'default', which queries the platform for the preferred input type).
  675. func (p SynthesizeTapGestureParams) WithGestureSourceType(gestureSourceType GestureSourceType) *SynthesizeTapGestureParams {
  676. p.GestureSourceType = gestureSourceType
  677. return &p
  678. }
  679. // Do executes Input.synthesizeTapGesture against the provided context.
  680. func (p *SynthesizeTapGestureParams) Do(ctx context.Context) (err error) {
  681. return cdp.Execute(ctx, CommandSynthesizeTapGesture, p, nil)
  682. }
  683. // Command names.
  684. const (
  685. CommandDispatchDragEvent = "Input.dispatchDragEvent"
  686. CommandDispatchKeyEvent = "Input.dispatchKeyEvent"
  687. CommandInsertText = "Input.insertText"
  688. CommandImeSetComposition = "Input.imeSetComposition"
  689. CommandDispatchMouseEvent = "Input.dispatchMouseEvent"
  690. CommandDispatchTouchEvent = "Input.dispatchTouchEvent"
  691. CommandCancelDragging = "Input.cancelDragging"
  692. CommandEmulateTouchFromMouseEvent = "Input.emulateTouchFromMouseEvent"
  693. CommandSetIgnoreInputEvents = "Input.setIgnoreInputEvents"
  694. CommandSetInterceptDrags = "Input.setInterceptDrags"
  695. CommandSynthesizePinchGesture = "Input.synthesizePinchGesture"
  696. CommandSynthesizeScrollGesture = "Input.synthesizeScrollGesture"
  697. CommandSynthesizeTapGesture = "Input.synthesizeTapGesture"
  698. )